diff options
author | Damian Gryski <[email protected]> | 2023-03-11 16:03:38 -0800 |
---|---|---|
committer | Ron Evans <[email protected]> | 2023-03-25 22:32:29 +0100 |
commit | 63c7a41337741eea97304e5c7a65880421d4e8b5 (patch) | |
tree | b76b2042118fd9981950ca84f2ea54a52df7b710 | |
parent | c0f8f129c08f8350ba479fe52dfe569722320134 (diff) | |
download | tinygo-63c7a41337741eea97304e5c7a65880421d4e8b5.tar.gz tinygo-63c7a41337741eea97304e5c7a65880421d4e8b5.zip |
reflect: convert non-interface to interface in Set()
-rw-r--r-- | src/reflect/value.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/reflect/value.go b/src/reflect/value.go index 5c4fffc45..67580dc21 100644 --- a/src/reflect/value.go +++ b/src/reflect/value.go @@ -910,6 +910,15 @@ func (v Value) Set(x Value) { if !v.typecode.AssignableTo(x.typecode) { panic("reflect: cannot set") } + + if v.typecode.Kind() == Interface && x.typecode.Kind() != Interface { + intf := composeInterface(unsafe.Pointer(x.typecode), x.value) + x = Value{ + typecode: v.typecode, + value: unsafe.Pointer(&intf), + } + } + size := v.typecode.Size() xptr := x.value if size <= unsafe.Sizeof(uintptr(0)) && !x.isIndirect() { |