Getting DeepEqual to work with maps whose key is an interface (#4360)

reflect: Getting DeepEqual to work with maps whose key is an interface
This commit is contained in:
Laurent Demailly
2024-07-23 15:30:02 -07:00
committed by GitHub
parent 61d36fb3f8
commit 1fd75ffbda
2 changed files with 19 additions and 1 deletions
+3 -1
View File
@@ -982,7 +982,9 @@ func (v Value) MapIndex(key Value) Value {
vkey := v.typecode.key()
// compare key type with actual key type of map
if !key.typecode.AssignableTo(vkey) {
// AssignableTo is not implemented for interfaces
// avoid: "reflect: unimplemented: AssignableTo with interface"
if vkey.Kind() != Interface && !key.typecode.AssignableTo(vkey) {
// type error?
panic("reflect.Value.MapIndex: incompatible types for key")
}