reflect: convert non-interface to interface in Set()

This commit is contained in:
Damian Gryski
2023-03-11 16:03:38 -08:00
committed by Ron Evans
parent c0f8f129c0
commit 63c7a41337
+9
View File
@@ -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() {