reflect: handle map-keys-as-interfaces for MapIter()
Этот коммит содержится в:
родитель
3612b7749e
коммит
bedd27b20e
1 изменённых файлов: 14 добавлений и 3 удалений
|
@ -846,9 +846,13 @@ func (v Value) MapRange() *MapIter {
|
|||
panic(&ValueError{Method: "MapRange", Kind: v.Kind()})
|
||||
}
|
||||
|
||||
keyType := v.typecode.Key().(*rawType)
|
||||
isKeyStoredAsInterface := keyType.Kind() != String && !keyType.isBinary()
|
||||
|
||||
return &MapIter{
|
||||
m: v,
|
||||
it: hashmapNewIterator(),
|
||||
keyInterface: isKeyStoredAsInterface,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -859,6 +863,7 @@ type MapIter struct {
|
|||
val Value
|
||||
|
||||
valid bool
|
||||
keyInterface bool
|
||||
}
|
||||
|
||||
func (it *MapIter) Key() Value {
|
||||
|
@ -866,6 +871,12 @@ func (it *MapIter) Key() Value {
|
|||
panic("reflect.MapIter.Key called on invalid iterator")
|
||||
}
|
||||
|
||||
if it.keyInterface {
|
||||
intf := *(*interface{})(it.key.value)
|
||||
v := ValueOf(intf)
|
||||
return v
|
||||
}
|
||||
|
||||
return it.key.Elem()
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче