// emptyStruct is the type we compile into when ignoring a struct value.
type emptyStruct struct{}
-var emptyStructType = reflect.TypeOf((*emptyStruct)(nil)).Elem()
+var emptyStructType = reflect.TypeFor[emptyStruct]()
// getIgnoreEnginePtr returns the engine for the specified type when the value is to be discarded.
func (dec *Decoder) getIgnoreEnginePtr(wireId typeId) (enginePtr **decEngine, err error) {
}
var (
- gobEncoderInterfaceType = reflect.TypeOf((*GobEncoder)(nil)).Elem()
- gobDecoderInterfaceType = reflect.TypeOf((*GobDecoder)(nil)).Elem()
- binaryMarshalerInterfaceType = reflect.TypeOf((*encoding.BinaryMarshaler)(nil)).Elem()
- binaryUnmarshalerInterfaceType = reflect.TypeOf((*encoding.BinaryUnmarshaler)(nil)).Elem()
- textMarshalerInterfaceType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem()
- textUnmarshalerInterfaceType = reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem()
-
- wireTypeType = reflect.TypeOf((*wireType)(nil)).Elem()
+ gobEncoderInterfaceType = reflect.TypeFor[GobEncoder]()
+ gobDecoderInterfaceType = reflect.TypeFor[GobDecoder]()
+ binaryMarshalerInterfaceType = reflect.TypeFor[encoding.BinaryMarshaler]()
+ binaryUnmarshalerInterfaceType = reflect.TypeFor[encoding.BinaryUnmarshaler]()
+ textMarshalerInterfaceType = reflect.TypeFor[encoding.TextMarshaler]()
+ textUnmarshalerInterfaceType = reflect.TypeFor[encoding.TextUnmarshaler]()
+
+ wireTypeType = reflect.TypeFor[wireType]()
)
// implementsInterface reports whether the type implements the
func init() {
// Some magic numbers to make sure there are no surprises.
checkId(16, tWireType)
- checkId(17, mustGetTypeInfo(reflect.TypeOf((*arrayType)(nil)).Elem()).id)
- checkId(18, mustGetTypeInfo(reflect.TypeOf((*CommonType)(nil)).Elem()).id)
- checkId(19, mustGetTypeInfo(reflect.TypeOf((*sliceType)(nil)).Elem()).id)
- checkId(20, mustGetTypeInfo(reflect.TypeOf((*structType)(nil)).Elem()).id)
- checkId(21, mustGetTypeInfo(reflect.TypeOf((*fieldType)(nil)).Elem()).id)
- checkId(23, mustGetTypeInfo(reflect.TypeOf((*mapType)(nil)).Elem()).id)
+ checkId(17, mustGetTypeInfo(reflect.TypeFor[arrayType]()).id)
+ checkId(18, mustGetTypeInfo(reflect.TypeFor[CommonType]()).id)
+ checkId(19, mustGetTypeInfo(reflect.TypeFor[sliceType]()).id)
+ checkId(20, mustGetTypeInfo(reflect.TypeFor[structType]()).id)
+ checkId(21, mustGetTypeInfo(reflect.TypeFor[fieldType]()).id)
+ checkId(23, mustGetTypeInfo(reflect.TypeFor[mapType]()).id)
copy(builtinIdToTypeSlice[:], idToType)
// Reregister some basic types to check registration is idempotent.
func TestReregistration(t *testing.T) {
- newtyp := getTypeUnlocked("int", reflect.TypeOf(int(0)))
+ newtyp := getTypeUnlocked("int", reflect.TypeFor[int]())
if newtyp != tInt.gobType() {
t.Errorf("reregistration of %s got new type", newtyp.string())
}
- newtyp = getTypeUnlocked("uint", reflect.TypeOf(uint(0)))
+ newtyp = getTypeUnlocked("uint", reflect.TypeFor[uint]())
if newtyp != tUint.gobType() {
t.Errorf("reregistration of %s got new type", newtyp.string())
}
- newtyp = getTypeUnlocked("string", reflect.TypeOf("hello"))
+ newtyp = getTypeUnlocked("string", reflect.TypeFor[string]())
if newtyp != tString.gobType() {
t.Errorf("reregistration of %s got new type", newtyp.string())
}
}
func TestStructType(t *testing.T) {
- sstruct := getTypeUnlocked("Foo", reflect.TypeOf(Foo{}))
+ sstruct := getTypeUnlocked("Foo", reflect.TypeFor[Foo]())
str := sstruct.string()
// If we can print it correctly, we built it correctly.
expected := "Foo = struct { A int; B int; C string; D bytes; E float; F float; G Bar = struct { X string; }; H Bar; I Foo; }"