mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-04 02:57:46 +00:00
reflect: handle map-keys-as-interfaces for MapIter()
This commit is contained in:
+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(),
|
||||
m: v,
|
||||
it: hashmapNewIterator(),
|
||||
keyInterface: isKeyStoredAsInterface,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -858,7 +862,8 @@ type MapIter struct {
|
||||
key Value
|
||||
val Value
|
||||
|
||||
valid bool
|
||||
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()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user