reflect: unpack interfaces in MapKeys() if needed

This commit is contained in:
Damian Gryski
2023-03-16 21:23:17 -07:00
committed by Ron Evans
parent f7880e73d8
commit a5ddc68845
2 changed files with 24 additions and 1 deletions
+10 -1
View File
@@ -779,8 +779,17 @@ func (v Value) MapKeys() []Value {
k := New(v.typecode.Key())
e := New(v.typecode.Elem())
keyType := v.typecode.Key().(*rawType)
isKeyStoredAsInterface := keyType.Kind() != String && !keyType.isBinary()
for hashmapNext(v.pointer(), it, k.value, e.value) {
keys = append(keys, k.Elem())
if isKeyStoredAsInterface {
intf := *(*interface{})(k.value)
v := ValueOf(intf)
keys = append(keys, v)
} else {
keys = append(keys, k.Elem())
}
k = New(v.typecode.Key())
}