Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 95a895d

Browse files
committed
go/types: make Identical(nil, T) == Identical(T, nil)
Fixes #15173 Change-Id: I353756f7bc36db0d2b24d40c80771481b7b18f6b Reviewed-on: https://go-review.googlesource.com/21585 Reviewed-by: Brad Fitzpatrick <[email protected]> Run-TryBot: Brad Fitzpatrick <[email protected]>
1 parent 9cc9e95 commit 95a895d

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/go/types/api_test.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,3 +1042,20 @@ func f() {
10421042
}
10431043
}
10441044
}
1045+
1046+
func TestIdentical_issue15173(t *testing.T) {
1047+
// Identical should allow nil arguments and be symmetric.
1048+
for _, test := range []struct {
1049+
x, y Type
1050+
want bool
1051+
}{
1052+
{Typ[Int], Typ[Int], true},
1053+
{Typ[Int], nil, false},
1054+
{nil, Typ[Int], false},
1055+
{nil, nil, true},
1056+
} {
1057+
if got := Identical(test.x, test.y); got != test.want {
1058+
t.Errorf("Identical(%v, %v) = %t", test.x, test.y, got)
1059+
}
1060+
}
1061+
}

src/go/types/predicates.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ func identical(x, y Type, p *ifacePair) bool {
277277
return x.obj == y.obj
278278
}
279279

280+
case nil:
281+
280282
default:
281283
unreachable()
282284
}

0 commit comments

Comments
 (0)