Commit e7ee3b91 authored by Ian Lance Taylor's avatar Ian Lance Taylor

reflect: check that types match without calling TypeOf

gccgo fails this test before CL 115577.

Updates #25284

Change-Id: Id4550b7b3e268f3c294420ed31c57ad3f1002b5e
Reviewed-on: https://go-review.googlesource.com/115635
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: 's avatarThan McIntosh <thanm@google.com>
parent 2c01b7d6
......@@ -3918,8 +3918,8 @@ func TestOverflow(t *testing.T) {
}
}
func checkSameType(t *testing.T, x, y interface{}) {
if TypeOf(x) != TypeOf(y) {
func checkSameType(t *testing.T, x Type, y interface{}) {
if x != TypeOf(y) || TypeOf(Zero(x).Interface()) != TypeOf(y) {
t.Errorf("did not find preexisting type for %s (vs %s)", TypeOf(x), TypeOf(y))
}
}
......@@ -4048,7 +4048,7 @@ func TestArrayOf(t *testing.T) {
// check that type already in binary is found
type T int
checkSameType(t, Zero(ArrayOf(5, TypeOf(T(1)))).Interface(), [5]T{})
checkSameType(t, ArrayOf(5, TypeOf(T(1))), [5]T{})
}
func TestArrayOfGC(t *testing.T) {
......@@ -4184,7 +4184,7 @@ func TestSliceOf(t *testing.T) {
// check that type already in binary is found
type T1 int
checkSameType(t, Zero(SliceOf(TypeOf(T1(1)))).Interface(), []T1{})
checkSameType(t, SliceOf(TypeOf(T1(1))), []T1{})
}
func TestSliceOverflow(t *testing.T) {
......@@ -4398,7 +4398,7 @@ func TestStructOf(t *testing.T) {
})
})
// check that type already in binary is found
checkSameType(t, Zero(StructOf(fields[2:3])).Interface(), struct{ Y uint64 }{})
checkSameType(t, StructOf(fields[2:3]), struct{ Y uint64 }{})
}
func TestStructOfExportRules(t *testing.T) {
......@@ -4943,7 +4943,7 @@ func TestChanOf(t *testing.T) {
// check that type already in binary is found
type T1 int
checkSameType(t, Zero(ChanOf(BothDir, TypeOf(T1(1)))).Interface(), (chan T1)(nil))
checkSameType(t, ChanOf(BothDir, TypeOf(T1(1))), (chan T1)(nil))
}
func TestChanOfDir(t *testing.T) {
......@@ -4954,8 +4954,8 @@ func TestChanOfDir(t *testing.T) {
// check that type already in binary is found
type T1 int
checkSameType(t, Zero(ChanOf(RecvDir, TypeOf(T1(1)))).Interface(), (<-chan T1)(nil))
checkSameType(t, Zero(ChanOf(SendDir, TypeOf(T1(1)))).Interface(), (chan<- T1)(nil))
checkSameType(t, ChanOf(RecvDir, TypeOf(T1(1))), (<-chan T1)(nil))
checkSameType(t, ChanOf(SendDir, TypeOf(T1(1))), (chan<- T1)(nil))
// check String form of ChanDir
if crt.ChanDir().String() != "<-chan" {
......@@ -5031,7 +5031,7 @@ func TestMapOf(t *testing.T) {
}
// check that type already in binary is found
checkSameType(t, Zero(MapOf(TypeOf(V(0)), TypeOf(K("")))).Interface(), map[V]K(nil))
checkSameType(t, MapOf(TypeOf(V(0)), TypeOf(K(""))), map[V]K(nil))
// check that invalid key type panics
shouldPanic(func() { MapOf(TypeOf((func())(nil)), TypeOf(false)) })
......@@ -5161,7 +5161,7 @@ func TestFuncOf(t *testing.T) {
{in: []Type{TypeOf(int(0))}, out: []Type{TypeOf(false), TypeOf("")}, want: (func(int) (bool, string))(nil)},
}
for _, tt := range testCases {
checkSameType(t, Zero(FuncOf(tt.in, tt.out, tt.variadic)).Interface(), tt.want)
checkSameType(t, FuncOf(tt.in, tt.out, tt.variadic), tt.want)
}
// check that variadic requires last element be a slice.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment