compiler: fix unsafe.Sizeof for chan and map values
These types are simply pointers. For some reason, they were never implemented. Fixes https://github.com/tinygo-org/tinygo/issues/3083.
Этот коммит содержится в:
родитель
9e8739bb47
коммит
b485e8bfbd
2 изменённых файлов: 3 добавлений и 1 удалений
|
@ -152,7 +152,7 @@ func (s *stdSizes) Sizeof(T types.Type) int64 {
|
||||||
return align(offsets[n-1]+s.Sizeof(fields[n-1].Type()), maxAlign)
|
return align(offsets[n-1]+s.Sizeof(fields[n-1].Type()), maxAlign)
|
||||||
case *types.Interface:
|
case *types.Interface:
|
||||||
return s.PtrSize * 2
|
return s.PtrSize * 2
|
||||||
case *types.Pointer:
|
case *types.Pointer, *types.Chan, *types.Map:
|
||||||
return s.PtrSize
|
return s.PtrSize
|
||||||
case *types.Signature:
|
case *types.Signature:
|
||||||
// Func values in TinyGo are two words in size.
|
// Func values in TinyGo are two words in size.
|
||||||
|
|
2
testdata/reflect.go
предоставленный
2
testdata/reflect.go
предоставленный
|
@ -175,6 +175,8 @@ func main() {
|
||||||
assertSize(reflect.TypeOf("").Size() == unsafe.Sizeof(""), "string")
|
assertSize(reflect.TypeOf("").Size() == unsafe.Sizeof(""), "string")
|
||||||
assertSize(reflect.TypeOf(new(int)).Size() == unsafe.Sizeof(new(int)), "*int")
|
assertSize(reflect.TypeOf(new(int)).Size() == unsafe.Sizeof(new(int)), "*int")
|
||||||
assertSize(reflect.TypeOf(zeroFunc).Size() == unsafe.Sizeof(zeroFunc), "func()")
|
assertSize(reflect.TypeOf(zeroFunc).Size() == unsafe.Sizeof(zeroFunc), "func()")
|
||||||
|
assertSize(reflect.TypeOf(zeroChan).Size() == unsafe.Sizeof(zeroChan), "chan int")
|
||||||
|
assertSize(reflect.TypeOf(zeroMap).Size() == unsafe.Sizeof(zeroMap), "map[string]int")
|
||||||
|
|
||||||
// make sure embedding a zero-sized "not comparable" struct does not add size to a struct
|
// make sure embedding a zero-sized "not comparable" struct does not add size to a struct
|
||||||
assertSize(reflect.TypeOf(doNotCompare{}).Size() == unsafe.Sizeof(doNotCompare{}), "[0]func()")
|
assertSize(reflect.TypeOf(doNotCompare{}).Size() == unsafe.Sizeof(doNotCompare{}), "[0]func()")
|
||||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче