mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-05 19:43:44 +00:00
reflect: don't construct an interface-in-interface value
v.Interaface() could construct an interface in interface value if v was of type interface. This is not correct, and doesn't follow upstream Go behavior. Instead, it should return the interface value itself.
This commit is contained in:
committed by
Ron Evans
parent
b534dd67e0
commit
d15e32fb89
@@ -67,6 +67,14 @@ func (v Value) Interface() interface{} {
|
||||
// valueInterfaceUnsafe is used by the runtime to hash map keys. It should not
|
||||
// be subject to the isExported check.
|
||||
func valueInterfaceUnsafe(v Value) interface{} {
|
||||
if v.typecode.Kind() == Interface {
|
||||
// The value itself is an interface. This can happen when getting the
|
||||
// value of a struct field of interface type, like this:
|
||||
// type T struct {
|
||||
// X interface{}
|
||||
// }
|
||||
return *(*interface{})(v.value)
|
||||
}
|
||||
if v.isIndirect() && v.typecode.Size() <= unsafe.Sizeof(uintptr(0)) {
|
||||
// Value was indirect but must be put back directly in the interface
|
||||
// value.
|
||||
|
||||
Reference in New Issue
Block a user