Skip to content

Commit

Permalink
Revert "Getting DeepEqual to work with maps whose key is an interface (
Browse files Browse the repository at this point in the history
…tinygo-org#4360)"

This reverts commit 1fd75ff.

The change is not correct and allows code to continue while it should
panic. For details, see:
tinygo-org#4360 (comment)
  • Loading branch information
aykevl committed Jul 29, 2024
1 parent 1fd75ff commit 6184a6c
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 19 deletions.
16 changes: 0 additions & 16 deletions src/reflect/all_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1102,20 +1102,6 @@ func init() {
cycleMap3["different"] = cycleMap3
}

type deepEqualInterface interface {
Foo()
}
type deepEqualConcrete struct {
int
}

func (deepEqualConcrete) Foo() {}

var (
deepEqualConcrete1 = deepEqualConcrete{1}
deepEqualConcrete2 = deepEqualConcrete{2}
)

var deepEqualTests = []DeepEqualTest{
// Equalities
{nil, nil, true},
Expand All @@ -1133,7 +1119,6 @@ var deepEqualTests = []DeepEqualTest{
{[]byte{1, 2, 3}, []byte{1, 2, 3}, true},
{[]MyByte{1, 2, 3}, []MyByte{1, 2, 3}, true},
{MyBytes{1, 2, 3}, MyBytes{1, 2, 3}, true},
{map[deepEqualInterface]string{deepEqualConcrete1: "a"}, map[deepEqualInterface]string{deepEqualConcrete1: "a"}, true},

// Inequalities
{1, 2, false},
Expand All @@ -1155,7 +1140,6 @@ var deepEqualTests = []DeepEqualTest{
{fn3, fn3, false},
{[][]int{{1}}, [][]int{{2}}, false},
{&structWithSelfPtr{p: &structWithSelfPtr{s: "a"}}, &structWithSelfPtr{p: &structWithSelfPtr{s: "b"}}, false},
{map[deepEqualInterface]string{deepEqualConcrete1: "a"}, map[deepEqualInterface]string{deepEqualConcrete2: "a"}, false},

// Fun with floating point.
{math.NaN(), math.NaN(), false},
Expand Down
4 changes: 1 addition & 3 deletions src/reflect/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -982,9 +982,7 @@ func (v Value) MapIndex(key Value) Value {
vkey := v.typecode.key()

// compare key type with actual key type of map
// AssignableTo is not implemented for interfaces
// avoid: "reflect: unimplemented: AssignableTo with interface"
if vkey.Kind() != Interface && !key.typecode.AssignableTo(vkey) {
if !key.typecode.AssignableTo(vkey) {
// type error?
panic("reflect.Value.MapIndex: incompatible types for key")
}
Expand Down

0 comments on commit 6184a6c

Please sign in to comment.