aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/reflect
diff options
context:
space:
mode:
authorDamian Gryski <[email protected]>2023-03-11 16:03:38 -0800
committerRon Evans <[email protected]>2023-03-25 22:32:29 +0100
commit63c7a41337741eea97304e5c7a65880421d4e8b5 (patch)
treeb76b2042118fd9981950ca84f2ea54a52df7b710 /src/reflect
parentc0f8f129c08f8350ba479fe52dfe569722320134 (diff)
downloadtinygo-63c7a41337741eea97304e5c7a65880421d4e8b5.tar.gz
tinygo-63c7a41337741eea97304e5c7a65880421d4e8b5.zip
reflect: convert non-interface to interface in Set()
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/value.go9
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() {