Skip to content

Commit b485e8b

Browse files
committed
compiler: fix unsafe.Sizeof for chan and map values
These types are simply pointers. For some reason, they were never implemented. Fixes #3083.
1 parent 9e8739b commit b485e8b

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

compiler/sizes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (s *stdSizes) Sizeof(T types.Type) int64 {
152152
return align(offsets[n-1]+s.Sizeof(fields[n-1].Type()), maxAlign)
153153
case *types.Interface:
154154
return s.PtrSize * 2
155-
case *types.Pointer:
155+
case *types.Pointer, *types.Chan, *types.Map:
156156
return s.PtrSize
157157
case *types.Signature:
158158
// Func values in TinyGo are two words in size.

testdata/reflect.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ func main() {
175175
assertSize(reflect.TypeOf("").Size() == unsafe.Sizeof(""), "string")
176176
assertSize(reflect.TypeOf(new(int)).Size() == unsafe.Sizeof(new(int)), "*int")
177177
assertSize(reflect.TypeOf(zeroFunc).Size() == unsafe.Sizeof(zeroFunc), "func()")
178+
assertSize(reflect.TypeOf(zeroChan).Size() == unsafe.Sizeof(zeroChan), "chan int")
179+
assertSize(reflect.TypeOf(zeroMap).Size() == unsafe.Sizeof(zeroMap), "map[string]int")
178180

179181
// make sure embedding a zero-sized "not comparable" struct does not add size to a struct
180182
assertSize(reflect.TypeOf(doNotCompare{}).Size() == unsafe.Sizeof(doNotCompare{}), "[0]func()")

0 commit comments

Comments
 (0)