You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This line in type.go:
tInterface = bootstrapType("interface", interface{}(nil), 8)
passes a nil to bootstrapType, which calls reflect.NewValue,
which returns a nil reflect.Type. This manages to pass all the
way through validUserType without causing a crash, because the
type assertion comma-ok form simply fails if an interface is nil.
So the code ends up filling in userTypeCache[nil] with apparently
no ill effect.
Still it's probably not the intent. One way to address this would
be to pass pointers to bootstrapType:
var (
// Primordial types, needed during initialization.
tBool = bootstrapType("bool", new(bool), 1)
tInt = bootstrapType("int", new(int), 2)
tUint = bootstrapType("uint", new(uint), 3)
tFloat = bootstrapType("float", new(float64), 4)
tBytes = bootstrapType("bytes", new([]byte), 5)
tString = bootstrapType("string", new(string), 6)
tComplex = bootstrapType("complex", new(complex128), 7)
tInterface = bootstrapType("interface", new(interface{}), 8)
// Reserve some Ids for compatible expansion
tReserved7 = bootstrapType("_reserved1", new(struct{ r7 int }), 9)
tReserved6 = bootstrapType("_reserved1", new(struct{ r6 int }), 10)
tReserved5 = bootstrapType("_reserved1", new(struct{ r5 int }), 11)
tReserved4 = bootstrapType("_reserved1", new(struct{ r4 int }), 12)
tReserved3 = bootstrapType("_reserved1", new(struct{ r3 int }), 13)
tReserved2 = bootstrapType("_reserved1", new(struct{ r2 int }), 14)
tReserved1 = bootstrapType("_reserved1", new(struct{ r1 int }), 15)
)
and then the first line of bootstrapType would be
rt := reflect.Typeof(e).(*reflect.PtrType).Elem()
I tried this and it still passes the unit tests but I don't know
if there is some subtle effect that is not being caught.
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: