diff --git a/src/crypto/internal/fips140/edwards25519/edwards25519_test.go b/src/crypto/internal/fips140/edwards25519/edwards25519_test.go
index 5f85e39..921162b 100644
--- a/src/crypto/internal/fips140/edwards25519/edwards25519_test.go
+++ b/src/crypto/internal/fips140/edwards25519/edwards25519_test.go
@@ -87,7 +87,7 @@
}
func TestComparable(t *testing.T) {
- if reflect.TypeOf(Point{}).Comparable() {
+ if reflect.TypeFor[Point]().Comparable() {
t.Error("Point is unexpectedly comparable")
}
}
diff --git a/src/crypto/x509/pkcs8_test.go b/src/crypto/x509/pkcs8_test.go
index d032880..6bfe2f9 100644
--- a/src/crypto/x509/pkcs8_test.go
+++ b/src/crypto/x509/pkcs8_test.go
@@ -65,41 +65,41 @@
{
name: "RSA private key",
keyHex: pkcs8RSAPrivateKeyHex,
- keyType: reflect.TypeOf(&rsa.PrivateKey{}),
+ keyType: reflect.TypeFor[*rsa.PrivateKey](),
},
{
name: "P-224 private key",
keyHex: pkcs8P224PrivateKeyHex,
- keyType: reflect.TypeOf(&ecdsa.PrivateKey{}),
+ keyType: reflect.TypeFor[*ecdsa.PrivateKey](),
curve: elliptic.P224(),
},
{
name: "P-256 private key",
keyHex: pkcs8P256PrivateKeyHex,
- keyType: reflect.TypeOf(&ecdsa.PrivateKey{}),
+ keyType: reflect.TypeFor[*ecdsa.PrivateKey](),
curve: elliptic.P256(),
},
{
name: "P-384 private key",
keyHex: pkcs8P384PrivateKeyHex,
- keyType: reflect.TypeOf(&ecdsa.PrivateKey{}),
+ keyType: reflect.TypeFor[*ecdsa.PrivateKey](),
curve: elliptic.P384(),
},
{
name: "P-521 private key",
keyHex: pkcs8P521PrivateKeyHex,
- keyType: reflect.TypeOf(&ecdsa.PrivateKey{}),
+ keyType: reflect.TypeFor[*ecdsa.PrivateKey](),
curve: elliptic.P521(),
},
{
name: "Ed25519 private key",
keyHex: pkcs8Ed25519PrivateKeyHex,
- keyType: reflect.TypeOf(ed25519.PrivateKey{}),
+ keyType: reflect.TypeFor[ed25519.PrivateKey](),
},
{
name: "X25519 private key",
keyHex: pkcs8X25519PrivateKeyHex,
- keyType: reflect.TypeOf(&ecdh.PrivateKey{}),
+ keyType: reflect.TypeFor[*ecdh.PrivateKey](),
},
}
diff --git a/src/encoding/asn1/marshal_test.go b/src/encoding/asn1/marshal_test.go
index dfd6d4e..3502856 100644
--- a/src/encoding/asn1/marshal_test.go
+++ b/src/encoding/asn1/marshal_test.go
@@ -284,7 +284,7 @@
t.Errorf("%v", err)
return
}
- if reflect.TypeOf(v).String() != reflect.TypeOf(ObjectIdentifier{}).String() {
+ if reflect.TypeOf(v).String() != reflect.TypeFor[ObjectIdentifier]().String() {
t.Errorf("marshal OID returned an invalid type")
return
}
diff --git a/src/encoding/gob/type_test.go b/src/encoding/gob/type_test.go
index 220058f..c7f3961 100644
--- a/src/encoding/gob/type_test.go
+++ b/src/encoding/gob/type_test.go
@@ -64,19 +64,16 @@
}
func TestArrayType(t *testing.T) {
- var a3 [3]int
- a3int := getTypeUnlocked("foo", reflect.TypeOf(a3))
- newa3int := getTypeUnlocked("bar", reflect.TypeOf(a3))
+ a3int := getTypeUnlocked("foo", reflect.TypeFor[[3]int]())
+ newa3int := getTypeUnlocked("bar", reflect.TypeFor[[3]int]())
if a3int != newa3int {
t.Errorf("second registration of [3]int creates new type")
}
- var a4 [4]int
- a4int := getTypeUnlocked("goo", reflect.TypeOf(a4))
+ a4int := getTypeUnlocked("goo", reflect.TypeFor[[4]int]())
if a3int == a4int {
t.Errorf("registration of [3]int creates same type as [4]int")
}
- var b3 [3]bool
- a3bool := getTypeUnlocked("", reflect.TypeOf(b3))
+ a3bool := getTypeUnlocked("", reflect.TypeFor[[3]bool]())
if a3int == a3bool {
t.Errorf("registration of [3]bool creates same type as [3]int")
}
@@ -88,15 +85,12 @@
}
func TestSliceType(t *testing.T) {
- var s []int
- sint := getTypeUnlocked("slice", reflect.TypeOf(s))
- var news []int
- newsint := getTypeUnlocked("slice1", reflect.TypeOf(news))
+ sint := getTypeUnlocked("slice", reflect.TypeFor[[]int]())
+ newsint := getTypeUnlocked("slice1", reflect.TypeFor[[]int]())
if sint != newsint {
t.Errorf("second registration of []int creates new type")
}
- var b []bool
- sbool := getTypeUnlocked("", reflect.TypeOf(b))
+ sbool := getTypeUnlocked("", reflect.TypeFor[[]bool]())
if sbool == sint {
t.Errorf("registration of []bool creates same type as []int")
}
@@ -108,15 +102,12 @@
}
func TestMapType(t *testing.T) {
- var m map[string]int
- mapStringInt := getTypeUnlocked("map", reflect.TypeOf(m))
- var newm map[string]int
- newMapStringInt := getTypeUnlocked("map1", reflect.TypeOf(newm))
+ mapStringInt := getTypeUnlocked("map", reflect.TypeFor[map[string]int]())
+ newMapStringInt := getTypeUnlocked("map1", reflect.TypeFor[map[string]int]())
if mapStringInt != newMapStringInt {
t.Errorf("second registration of map[string]int creates new type")
}
- var b map[string]bool
- mapStringBool := getTypeUnlocked("", reflect.TypeOf(b))
+ mapStringBool := getTypeUnlocked("", reflect.TypeFor[map[string]bool]())
if mapStringBool == mapStringInt {
t.Errorf("registration of map[string]bool creates same type as map[string]int")
}
diff --git a/src/encoding/json/encode_test.go b/src/encoding/json/encode_test.go
index 87074ea..e67b75c 100644
--- a/src/encoding/json/encode_test.go
+++ b/src/encoding/json/encode_test.go
@@ -1352,8 +1352,7 @@
}
func TestMarshalerError(t *testing.T) {
- s := "test variable"
- st := reflect.TypeOf(s)
+ st := reflect.TypeFor[string]()
const errText = "json: test error"
tests := []struct {
diff --git a/src/fmt/scan_test.go b/src/fmt/scan_test.go
index 17e5ccf..6274103 100644
--- a/src/fmt/scan_test.go
+++ b/src/fmt/scan_test.go
@@ -640,7 +640,7 @@
}
func testScanfMulti(t *testing.T, f func(string) io.Reader) {
- sliceType := reflect.TypeOf(make([]any, 1))
+ sliceType := reflect.TypeFor[[]any]()
for _, test := range multiTests {
r := f(test.text)
n, err := Fscanf(r, test.format, test.in...)
diff --git a/src/internal/fmtsort/sort_test.go b/src/internal/fmtsort/sort_test.go
index 3f2b8a1..d54f5ee 100644
--- a/src/internal/fmtsort/sort_test.go
+++ b/src/internal/fmtsort/sort_test.go
@@ -18,28 +18,28 @@
)
var compareTests = [][]reflect.Value{
- ct(reflect.TypeOf(int(0)), -1, 0, 1),
- ct(reflect.TypeOf(int8(0)), -1, 0, 1),
- ct(reflect.TypeOf(int16(0)), -1, 0, 1),
- ct(reflect.TypeOf(int32(0)), -1, 0, 1),
- ct(reflect.TypeOf(int64(0)), -1, 0, 1),
- ct(reflect.TypeOf(uint(0)), 0, 1, 5),
- ct(reflect.TypeOf(uint8(0)), 0, 1, 5),
- ct(reflect.TypeOf(uint16(0)), 0, 1, 5),
- ct(reflect.TypeOf(uint32(0)), 0, 1, 5),
- ct(reflect.TypeOf(uint64(0)), 0, 1, 5),
- ct(reflect.TypeOf(uintptr(0)), 0, 1, 5),
- ct(reflect.TypeOf(string("")), "", "a", "ab"),
- ct(reflect.TypeOf(float32(0)), math.NaN(), math.Inf(-1), -1e10, 0, 1e10, math.Inf(1)),
- ct(reflect.TypeOf(float64(0)), math.NaN(), math.Inf(-1), -1e10, 0, 1e10, math.Inf(1)),
- ct(reflect.TypeOf(complex64(0+1i)), -1-1i, -1+0i, -1+1i, 0-1i, 0+0i, 0+1i, 1-1i, 1+0i, 1+1i),
- ct(reflect.TypeOf(complex128(0+1i)), -1-1i, -1+0i, -1+1i, 0-1i, 0+0i, 0+1i, 1-1i, 1+0i, 1+1i),
- ct(reflect.TypeOf(false), false, true),
- ct(reflect.TypeOf(&ints[0]), &ints[0], &ints[1], &ints[2]),
- ct(reflect.TypeOf(unsafe.Pointer(&ints[0])), unsafe.Pointer(&ints[0]), unsafe.Pointer(&ints[1]), unsafe.Pointer(&ints[2])),
- ct(reflect.TypeOf(chans[0]), chans[0], chans[1], chans[2]),
- ct(reflect.TypeOf(toy{}), toy{0, 1}, toy{0, 2}, toy{1, -1}, toy{1, 1}),
- ct(reflect.TypeOf([2]int{}), [2]int{1, 1}, [2]int{1, 2}, [2]int{2, 0}),
+ ct(reflect.TypeFor[int](), -1, 0, 1),
+ ct(reflect.TypeFor[int8](), -1, 0, 1),
+ ct(reflect.TypeFor[int16](), -1, 0, 1),
+ ct(reflect.TypeFor[int32](), -1, 0, 1),
+ ct(reflect.TypeFor[int64](), -1, 0, 1),
+ ct(reflect.TypeFor[uint](), 0, 1, 5),
+ ct(reflect.TypeFor[uint8](), 0, 1, 5),
+ ct(reflect.TypeFor[uint16](), 0, 1, 5),
+ ct(reflect.TypeFor[uint32](), 0, 1, 5),
+ ct(reflect.TypeFor[uint64](), 0, 1, 5),
+ ct(reflect.TypeFor[uintptr](), 0, 1, 5),
+ ct(reflect.TypeFor[string](), "", "a", "ab"),
+ ct(reflect.TypeFor[float32](), math.NaN(), math.Inf(-1), -1e10, 0, 1e10, math.Inf(1)),
+ ct(reflect.TypeFor[float64](), math.NaN(), math.Inf(-1), -1e10, 0, 1e10, math.Inf(1)),
+ ct(reflect.TypeFor[complex64](), -1-1i, -1+0i, -1+1i, 0-1i, 0+0i, 0+1i, 1-1i, 1+0i, 1+1i),
+ ct(reflect.TypeFor[complex128](), -1-1i, -1+0i, -1+1i, 0-1i, 0+0i, 0+1i, 1-1i, 1+0i, 1+1i),
+ ct(reflect.TypeFor[bool](), false, true),
+ ct(reflect.TypeFor[*int](), &ints[0], &ints[1], &ints[2]),
+ ct(reflect.TypeFor[unsafe.Pointer](), unsafe.Pointer(&ints[0]), unsafe.Pointer(&ints[1]), unsafe.Pointer(&ints[2])),
+ ct(reflect.TypeFor[chan int](), chans[0], chans[1], chans[2]),
+ ct(reflect.TypeFor[toy](), toy{0, 1}, toy{0, 2}, toy{1, -1}, toy{1, 1}),
+ ct(reflect.TypeFor[[2]int](), [2]int{1, 1}, [2]int{1, 2}, [2]int{2, 0}),
ct(reflect.TypeOf(any(0)), iFace, 1, 2, 3),
}
diff --git a/src/internal/fuzz/minimize.go b/src/internal/fuzz/minimize.go
index 0e410fb..d5996a1 100644
--- a/src/internal/fuzz/minimize.go
+++ b/src/internal/fuzz/minimize.go
@@ -9,7 +9,7 @@
)
func isMinimizable(t reflect.Type) bool {
- return t == reflect.TypeOf("") || t == reflect.TypeOf([]byte(nil))
+ return t == reflect.TypeFor[string]() || t == reflect.TypeFor[[]byte]()
}
func minimizeBytes(v []byte, try func([]byte) bool, shouldStop func() bool) {
diff --git a/src/internal/fuzz/worker_test.go b/src/internal/fuzz/worker_test.go
index 9420248..26c24ff 100644
--- a/src/internal/fuzz/worker_test.go
+++ b/src/internal/fuzz/worker_test.go
@@ -120,7 +120,7 @@
func newWorkerForTest(tb testing.TB) *worker {
tb.Helper()
c, err := newCoordinator(CoordinateFuzzingOpts{
- Types: []reflect.Type{reflect.TypeOf([]byte(nil))},
+ Types: []reflect.Type{reflect.TypeFor[[]byte]()},
Log: io.Discard,
})
if err != nil {
diff --git a/src/internal/synctest/synctest_test.go b/src/internal/synctest/synctest_test.go
index 75aa411..be5a603 100644
--- a/src/internal/synctest/synctest_test.go
+++ b/src/internal/synctest/synctest_test.go
@@ -650,7 +650,7 @@
reflect.FuncOf([]reflect.Type{
reflect.StructOf([]reflect.StructField{{
Name: name + strconv.Itoa(i),
- Type: reflect.TypeOf(0),
+ Type: reflect.TypeFor[int](),
}}),
}, nil, false)
}
diff --git a/src/internal/unsafeheader/unsafeheader_test.go b/src/internal/unsafeheader/unsafeheader_test.go
index f3d1a9b..b10785f 100644
--- a/src/internal/unsafeheader/unsafeheader_test.go
+++ b/src/internal/unsafeheader/unsafeheader_test.go
@@ -53,8 +53,8 @@
}
var (
- unsafePointerType = reflect.TypeOf(unsafe.Pointer(nil))
- uintptrType = reflect.TypeOf(uintptr(0))
+ unsafePointerType = reflect.TypeFor[unsafe.Pointer]()
+ uintptrType = reflect.TypeFor[uintptr]()
)
func typeCompatible(t, rt reflect.Type) bool {
diff --git a/src/reflect/abi_test.go b/src/reflect/abi_test.go
index 576f288..3e19429 100644
--- a/src/reflect/abi_test.go
+++ b/src/reflect/abi_test.go
@@ -233,8 +233,7 @@
// to a location visible to the GC, the object should be
// freed and then the next GC should notice that an object
// was inexplicably revived.
- var f func(b *uint64, _ MagicLastTypeNameForTestingRegisterABI) *uint64
- mkfn := reflect.MakeFunc(reflect.TypeOf(f), func(args []reflect.Value) []reflect.Value {
+ mkfn := reflect.MakeFunc(reflect.TypeFor[func(b *uint64, _ MagicLastTypeNameForTestingRegisterABI) *uint64](), func(args []reflect.Value) []reflect.Value {
*(args[0].Interface().(*uint64)) = 5
return args[:1]
})
diff --git a/src/reflect/example_test.go b/src/reflect/example_test.go
index bcc2303..58a034e 100644
--- a/src/reflect/example_test.go
+++ b/src/reflect/example_test.go
@@ -78,8 +78,7 @@
F string `species:"gopher" color:"blue"`
}
- s := S{}
- st := reflect.TypeOf(s)
+ st := reflect.TypeFor[S]()
field := st.Field(0)
fmt.Println(field.Tag.Get("color"), field.Tag.Get("species"))
@@ -94,8 +93,7 @@
F2 string
}
- s := S{}
- st := reflect.TypeOf(s)
+ st := reflect.TypeFor[S]()
for field := range st.Fields() {
if alias, ok := field.Tag.Lookup("alias"); ok {
if alias == "" {
@@ -118,9 +116,9 @@
// As interface types are only used for static typing, a
// common idiom to find the reflection Type for an interface
// type Foo is to use a *Foo value.
- writerType := reflect.TypeOf((*io.Writer)(nil)).Elem()
+ writerType := reflect.TypeFor[io.Writer]()
- fileType := reflect.TypeOf((*os.File)(nil))
+ fileType := reflect.TypeFor[*os.File]()
fmt.Println(fileType.Implements(writerType))
// Output:
@@ -131,12 +129,12 @@
typ := reflect.StructOf([]reflect.StructField{
{
Name: "Height",
- Type: reflect.TypeOf(float64(0)),
+ Type: reflect.TypeFor[float64](),
Tag: `json:"height"`,
},
{
Name: "Age",
- Type: reflect.TypeOf(int(0)),
+ Type: reflect.TypeFor[int](),
Tag: `json:"age"`,
},
})
diff --git a/src/reflect/iter_test.go b/src/reflect/iter_test.go
index 668d665..61e1f60 100644
--- a/src/reflect/iter_test.go
+++ b/src/reflect/iter_test.go
@@ -195,8 +195,8 @@
t.Fatalf("got %d, want %d", v.Int(), i)
}
i++
- if v.Type() != reflect.TypeOf(i) {
- t.Fatalf("got %s, want %s", v.Type(), reflect.TypeOf(i))
+ if v.Type() != reflect.TypeFor[N]() {
+ t.Fatalf("got %s, want %s", v.Type(), reflect.TypeFor[N]())
}
}
if i != 4 {
@@ -348,8 +348,8 @@
t.Fatalf("got %d, want %d", v2.Int(), i)
}
i++
- if v2.Type() != reflect.TypeOf(i) {
- t.Fatalf("got %s, want %s", v2.Type(), reflect.TypeOf(i))
+ if v2.Type() != reflect.TypeFor[N]() {
+ t.Fatalf("got %s, want %s", v2.Type(), reflect.TypeFor[N]())
}
}
if i != 4 {
@@ -366,8 +366,8 @@
if v2.Int() != int64(i) {
t.Fatalf("got %d, want %d", v2.Int(), i)
}
- if v2.Type() != reflect.TypeOf(i) {
- t.Fatalf("got %s, want %s", v2.Type(), reflect.TypeOf(i))
+ if v2.Type() != reflect.TypeFor[N]() {
+ t.Fatalf("got %s, want %s", v2.Type(), reflect.TypeFor[N]())
}
}
if i != 4 {
diff --git a/src/reflect/type_test.go b/src/reflect/type_test.go
index 00344c62..a0883df 100644
--- a/src/reflect/type_test.go
+++ b/src/reflect/type_test.go
@@ -70,30 +70,28 @@
args args
want bool
}{
- {"struct{i int}", args{reflect.TypeOf(struct{ i int }{})}, true},
- {"struct{}", args{reflect.TypeOf(struct{}{})}, true},
- {"struct{i int; s S}", args{reflect.TypeOf(struct {
+ {"struct{i int}", args{reflect.TypeFor[struct{ i int }]()}, true},
+ {"struct{}", args{reflect.TypeFor[struct{}]()}, true},
+ {"struct{i int; s S}", args{reflect.TypeFor[struct {
i int
s S
- }{})}, true},
- {"map[int][int]", args{reflect.TypeOf(map[int]int{})}, false},
- {"[4]chan int", args{reflect.TypeOf([4]chan int{})}, true},
- {"[0]struct{_ S}", args{reflect.TypeOf([0]struct {
- _ S
- }{})}, true},
- {"struct{i int; _ S}", args{reflect.TypeOf(struct {
+ }]()}, true},
+ {"map[int][int]", args{reflect.TypeFor[map[int]int]()}, false},
+ {"[4]chan int", args{reflect.TypeFor[[4]chan int]()}, true},
+ {"[0]struct{_ S}", args{reflect.TypeFor[[0]struct{ _ S }]()}, true},
+ {"struct{i int; _ S}", args{reflect.TypeFor[struct {
i int
_ S
- }{})}, false},
- {"struct{a int16; b int32}", args{reflect.TypeOf(struct {
+ }]()}, false},
+ {"struct{a int16; b int32}", args{reflect.TypeFor[struct {
a int16
b int32
- }{})}, false},
- {"struct {x int32; y int16}", args{reflect.TypeOf(struct {
+ }]()}, false},
+ {"struct {x int32; y int16}", args{reflect.TypeFor[struct {
x int32
y int16
- }{})}, false},
- {"struct {_ int32 }", args{reflect.TypeOf(struct{ _ int32 }{})}, false},
+ }]()}, false},
+ {"struct {_ int32 }", args{reflect.TypeFor[struct{ _ int32 }]()}, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -124,17 +122,17 @@
tr reflect.Type
want bool
}{
- {"func(func(int) bool)", reflect.TypeOf(func(func(int) bool) {}), true},
- {"func(func(int))", reflect.TypeOf(func(func(int)) {}), false},
+ {"func(func(int) bool)", reflect.TypeFor[func(func(int) bool)](), true},
+ {"func(func(int))", reflect.TypeFor[func(func(int))](), false},
{"methodIter.Seq", reflect.ValueOf(methodIter{}).MethodByName("Seq").Type(), true},
{"methodIter.NonSeq", reflect.ValueOf(methodIter{}).MethodByName("NonSeq").Type(), false},
- {"int64", reflect.TypeOf(int64(1)), true},
- {"uint64", reflect.TypeOf(uint64(1)), true},
- {"*[4]int", reflect.TypeOf(&[4]int{}), true},
- {"chan int64", reflect.TypeOf(make(chan int64)), true},
- {"map[int]int", reflect.TypeOf(make(map[int]int)), true},
- {"string", reflect.TypeOf(""), true},
- {"[]int", reflect.TypeOf([]int{}), true},
+ {"int64", reflect.TypeFor[int64](), true},
+ {"uint64", reflect.TypeFor[uint64](), true},
+ {"*[4]int", reflect.TypeFor[*[4]int](), true},
+ {"chan int64", reflect.TypeFor[chan int64](), true},
+ {"map[int]int", reflect.TypeFor[map[int]int](), true},
+ {"string", reflect.TypeFor[string](), true},
+ {"[]int", reflect.TypeFor[[]int](), true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
@@ -151,17 +149,17 @@
tr reflect.Type
want bool
}{
- {"func(func(int, int) bool)", reflect.TypeOf(func(func(int, int) bool) {}), true},
- {"func(func(int, int))", reflect.TypeOf(func(func(int, int)) {}), false},
+ {"func(func(int, int) bool)", reflect.TypeFor[func(func(int, int) bool)](), true},
+ {"func(func(int, int))", reflect.TypeFor[func(func(int, int))](), false},
{"methodIter2.Seq2", reflect.ValueOf(methodIter2{}).MethodByName("Seq2").Type(), true},
{"methodIter2.NonSeq2", reflect.ValueOf(methodIter2{}).MethodByName("NonSeq2").Type(), false},
- {"int64", reflect.TypeOf(int64(1)), false},
- {"uint64", reflect.TypeOf(uint64(1)), false},
- {"*[4]int", reflect.TypeOf(&[4]int{}), true},
- {"chan int64", reflect.TypeOf(make(chan int64)), false},
- {"map[int]int", reflect.TypeOf(make(map[int]int)), true},
- {"string", reflect.TypeOf(""), true},
- {"[]int", reflect.TypeOf([]int{}), true},
+ {"int64", reflect.TypeFor[int64](), false},
+ {"uint64", reflect.TypeFor[uint64](), false},
+ {"*[4]int", reflect.TypeFor[*[4]int](), true},
+ {"chan int64", reflect.TypeFor[chan int64](), false},
+ {"map[int]int", reflect.TypeFor[map[int]int](), true},
+ {"string", reflect.TypeFor[string](), true},
+ {"[]int", reflect.TypeFor[[]int](), true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
diff --git a/src/runtime/arena_test.go b/src/runtime/arena_test.go
index fdd8f7e..3a6d721 100644
--- a/src/runtime/arena_test.go
+++ b/src/runtime/arena_test.go
@@ -153,7 +153,7 @@
}
func runSubTestUserArenaNew[S comparable](t *testing.T, value *S, parallel bool) {
- t.Run(reflect.TypeOf(value).Elem().Name(), func(t *testing.T) {
+ t.Run(reflect.TypeFor[S]().Name(), func(t *testing.T) {
if parallel {
t.Parallel()
}
@@ -192,7 +192,7 @@
}
func runSubTestUserArenaSlice[S comparable](t *testing.T, value []S, parallel bool) {
- t.Run("[]"+reflect.TypeOf(value).Elem().Name(), func(t *testing.T) {
+ t.Run("[]"+reflect.TypeFor[[]S]().Elem().Name(), func(t *testing.T) {
if parallel {
t.Parallel()
}
diff --git a/src/runtime/malloc_test.go b/src/runtime/malloc_test.go
index 83ee826..1206230 100644
--- a/src/runtime/malloc_test.go
+++ b/src/runtime/malloc_test.go
@@ -50,7 +50,7 @@
return nil
}
- if reflect.ValueOf(x).Convert(reflect.TypeOf(thresh)).Float() < thresh {
+ if reflect.ValueOf(x).Convert(reflect.TypeFor[float64]()).Float() < thresh {
return nil
}
return fmt.Errorf("insanely high value (overflow?); want <= %v", thresh)
diff --git a/src/runtime/time_test.go b/src/runtime/time_test.go
index 6cd39e8..ac99138 100644
--- a/src/runtime/time_test.go
+++ b/src/runtime/time_test.go
@@ -101,7 +101,7 @@
// runtime.timeTimer (exported for testing as TimeTimer)
// must have time.Timer and time.Ticker as a prefix
// (meaning those two must have the same layout).
- runtimeTimeTimer := reflect.TypeOf(runtime.TimeTimer{})
+ runtimeTimeTimer := reflect.TypeFor[runtime.TimeTimer]()
check := func(name string, typ reflect.Type) {
n1 := runtimeTimeTimer.NumField()
@@ -124,6 +124,6 @@
}
}
- check("time.Timer", reflect.TypeOf(time.Timer{}))
- check("time.Ticker", reflect.TypeOf(time.Ticker{}))
+ check("time.Timer", reflect.TypeFor[time.Timer]())
+ check("time.Ticker", reflect.TypeFor[time.Ticker]())
}
diff --git a/src/sync/atomic/atomic_test.go b/src/sync/atomic/atomic_test.go
index 4fd78fe..e5ae336 100644
--- a/src/sync/atomic/atomic_test.go
+++ b/src/sync/atomic/atomic_test.go
@@ -2902,7 +2902,10 @@
_ uint32
i Int64
}
- if o := reflect.TypeOf(&signed).Elem().Field(1).Offset; o != 8 {
+ if o := reflect.TypeFor[struct {
+ _ uint32
+ i Int64
+ }]().Field(1).Offset; o != 8 {
t.Fatalf("Int64 offset = %d, want 8", o)
}
if p := reflect.ValueOf(&signed).Elem().Field(1).Addr().Pointer(); p&7 != 0 {
@@ -2913,7 +2916,10 @@
_ uint32
i Uint64
}
- if o := reflect.TypeOf(&unsigned).Elem().Field(1).Offset; o != 8 {
+ if o := reflect.TypeFor[struct {
+ _ uint32
+ i Uint64
+ }]().Field(1).Offset; o != 8 {
t.Fatalf("Uint64 offset = %d, want 8", o)
}
if p := reflect.ValueOf(&unsigned).Elem().Field(1).Addr().Pointer(); p&7 != 0 {