reflect: convert map elements to an interface, if needed

This commit is contained in:
Damian Gryski
2023-03-11 15:49:19 -08:00
committed by Ron Evans
parent adaa7ca27a
commit c0f8f129c0
2 changed files with 27 additions and 0 deletions
+9
View File
@@ -1370,6 +1370,15 @@ func (v Value) SetMapIndex(key, elem Value) {
panic("reflect.Value.SetMapIndex: incompatible types for value")
}
// make elem an interface if it needs to be converted
if v.typecode.elem().Kind() == Interface && elem.typecode.Kind() != Interface {
intf := composeInterface(unsafe.Pointer(elem.typecode), elem.value)
elem = Value{
typecode: v.typecode.elem(),
value: unsafe.Pointer(&intf),
}
}
if key.Kind() == String {
if del {
hashmapStringDelete(v.pointer(), *(*string)(key.value))