}
}
-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))
}
}
// 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) {
// 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) {
})
})
// 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) {
// 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) {
// 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" {
}
// 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)) })
{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.
ch.uncommonType = nil
ch.ptrToThis = nil
- ti, _ := lookupCache.LoadOrStore(ckey, &ch.rtype)
- return ti.(Type)
+ // Canonicalize before storing in lookupCache
+ ti := toType(&ch.rtype)
+ lookupCache.Store(ckey, ti.(*rtype))
+ return ti
}
func ismapkey(*rtype) bool // implemented in runtime
mt.reflexivekey = isReflexive(ktyp)
mt.needkeyupdate = needKeyUpdate(ktyp)
- ti, _ := lookupCache.LoadOrStore(ckey, &mt.rtype)
- return ti.(Type)
+ // Canonicalize before storing in lookupCache
+ ti := toType(&mt.rtype)
+ lookupCache.Store(ckey, ti.(*rtype))
+ return ti
}
// FuncOf returns the function type with the given argument and result types.
ft.string = &str
ft.uncommonType = nil
ft.ptrToThis = nil
- return addToCache(&ft.rtype)
+
+ // Canonicalize before storing in funcLookupCache
+ tc := toType(&ft.rtype)
+ return addToCache(tc.(*rtype))
}
// funcStr builds a string representation of a funcType.
slice.uncommonType = nil
slice.ptrToThis = nil
- ti, _ := lookupCache.LoadOrStore(ckey, &slice.rtype)
- return ti.(Type)
+ // Canonicalize before storing in lookupCache
+ ti := toType(&slice.rtype)
+ lookupCache.Store(ckey, ti.(*rtype))
+ return ti
}
// The structLookupCache caches StructOf lookups.
typ.uncommonType = nil
typ.ptrToThis = nil
- return addToCache(&typ.rtype)
+ // Canonicalize before storing in structLookupCache
+ ti := toType(&typ.rtype)
+ return addToCache(ti.(*rtype))
}
func runtimeStructField(field StructField) structField {
}
}
- ti, _ := lookupCache.LoadOrStore(ckey, &array.rtype)
- return ti.(Type)
+ // Canonicalize before storing in lookupCache
+ ti := toType(&array.rtype)
+ lookupCache.Store(ckey, ti.(*rtype))
+ return ti
}
func appendVarint(x []byte, v uintptr) []byte {