reflect: move indirect values into interface when setting interfaces

Fixes #4040
This commit is contained in:
Damian Gryski
2023-12-12 21:51:26 -08:00
committed by Ron Evans
parent cc3e785692
commit 5b8127fd4e
2 changed files with 29 additions and 0 deletions
+7
View File
@@ -1086,6 +1086,13 @@ func (v Value) Set(x Value) {
}
if v.typecode.Kind() == Interface && x.typecode.Kind() != Interface {
// move the value of x back into the interface, if possible
if x.isIndirect() && x.typecode.Size() <= unsafe.Sizeof(uintptr(0)) {
var value uintptr
memcpy(unsafe.Pointer(&value), x.value, x.typecode.Size())
x.value = unsafe.Pointer(value)
}
intf := composeInterface(unsafe.Pointer(x.typecode), x.value)
x = Value{
typecode: v.typecode,