reflect: fix iterating over maps with interface{} keys

Fixes #3794
This commit is contained in:
Damian Gryski
2023-06-16 12:19:53 -07:00
committed by Ron Evans
parent 93cc03b15a
commit ef72c5bb4e
2 changed files with 30 additions and 9 deletions
+18
View File
@@ -191,6 +191,24 @@ func TestTinyMap(t *testing.T) {
if _, ok := utIterKey.Interface().(unmarshalerText); !ok {
t.Errorf("Map keys via MapIter() have wrong type: %v", utIterKey.Type().String())
}
{
m := map[any]any{1: 2}
rv := ValueOf(m)
iter := rv.MapRange()
iter.Next()
k := iter.Key()
if k.Kind().String() != "interface" {
t.Errorf("map[any]any MapRange has wrong key type: %v", k.Kind().String())
}
keys := rv.MapKeys()
if k := keys[0]; k.Kind().String() != "interface" {
t.Errorf("map[any]any MapRange has wrong key type: %v", k.Kind().String())
}
}
}
// For an interface type, it returns the number of exported and unexported methods.