1
0
mirror of https://github.com/golang/go synced 2024-11-19 01:44:40 -07:00

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 <bradfitz@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Alan Donovan 2016-04-07 10:07:10 -04:00
parent 9cc9e95b28
commit 95a895df0c
2 changed files with 19 additions and 0 deletions

View File

@ -1042,3 +1042,20 @@ func f() {
}
}
}
func TestIdentical_issue15173(t *testing.T) {
// Identical should allow nil arguments and be symmetric.
for _, test := range []struct {
x, y Type
want bool
}{
{Typ[Int], Typ[Int], true},
{Typ[Int], nil, false},
{nil, Typ[Int], false},
{nil, nil, true},
} {
if got := Identical(test.x, test.y); got != test.want {
t.Errorf("Identical(%v, %v) = %t", test.x, test.y, got)
}
}
}

View File

@ -277,6 +277,8 @@ func identical(x, y Type, p *ifacePair) bool {
return x.obj == y.obj
}
case nil:
default:
unreachable()
}