Skip to content

Commit b93acc2

Browse files
cuishuanggopherbot
authored andcommitted
all: use reflect.TypeFor instead of reflect.TypeOf
For golang/go#60088. Change-Id: Ifc6d5cf0b94b977b2699e4781875bf75b9aa25c8 Reviewed-on: https://go-review.googlesource.com/c/net/+/709195 Reviewed-by: Michael Pratt <mpratt@google.com> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent 2002a06 commit b93acc2

File tree

5 files changed

+12
-12
lines changed

5 files changed

+12
-12
lines changed

http2/connframes_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ frame:
110110
if typ.Kind() != reflect.Func ||
111111
typ.NumIn() != 1 ||
112112
typ.NumOut() != 1 ||
113-
typ.Out(0) != reflect.TypeOf(true) {
113+
typ.Out(0) != reflect.TypeFor[bool]() {
114114
tf.t.Fatalf("expected func(*SomeFrame) bool, got %T", f)
115115
}
116116
if typ.In(0) == reflect.TypeOf(fr) {

webdav/internal/xml/marshal.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,9 @@ func (p *printer) setAttrPrefix(prefix, url string) {
546546
}
547547

548548
var (
549-
marshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem()
550-
marshalerAttrType = reflect.TypeOf((*MarshalerAttr)(nil)).Elem()
551-
textMarshalerType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem()
549+
marshalerType = reflect.TypeFor[Marshaler]()
550+
marshalerAttrType = reflect.TypeFor[MarshalerAttr]()
551+
textMarshalerType = reflect.TypeFor[encoding.TextMarshaler]()
552552
)
553553

554554
// marshalValue writes one or more XML elements representing val.

webdav/internal/xml/read.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,9 @@ func (p *Decoder) unmarshalAttr(val reflect.Value, attr Attr) error {
262262
}
263263

264264
var (
265-
unmarshalerType = reflect.TypeOf((*Unmarshaler)(nil)).Elem()
266-
unmarshalerAttrType = reflect.TypeOf((*UnmarshalerAttr)(nil)).Elem()
267-
textUnmarshalerType = reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem()
265+
unmarshalerType = reflect.TypeFor[Unmarshaler]()
266+
unmarshalerAttrType = reflect.TypeFor[UnmarshalerAttr]()
267+
textUnmarshalerType = reflect.TypeFor[encoding.TextUnmarshaler]()
268268
)
269269

270270
// Unmarshal a single XML element into val.

webdav/internal/xml/read_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,10 @@ type BadPathEmbeddedB struct {
325325
var badPathTests = []struct {
326326
v, e interface{}
327327
}{
328-
{&BadPathTestA{}, &TagPathError{reflect.TypeOf(BadPathTestA{}), "First", "items>item1", "Second", "items"}},
329-
{&BadPathTestB{}, &TagPathError{reflect.TypeOf(BadPathTestB{}), "First", "items>item1", "Second", "items>item1>value"}},
330-
{&BadPathTestC{}, &TagPathError{reflect.TypeOf(BadPathTestC{}), "First", "", "Second", "First"}},
331-
{&BadPathTestD{}, &TagPathError{reflect.TypeOf(BadPathTestD{}), "First", "", "Second", "First"}},
328+
{&BadPathTestA{}, &TagPathError{reflect.TypeFor[BadPathTestA](), "First", "items>item1", "Second", "items"}},
329+
{&BadPathTestB{}, &TagPathError{reflect.TypeFor[BadPathTestB](), "First", "items>item1", "Second", "items>item1>value"}},
330+
{&BadPathTestC{}, &TagPathError{reflect.TypeFor[BadPathTestC](), "First", "", "Second", "First"}},
331+
{&BadPathTestD{}, &TagPathError{reflect.TypeFor[BadPathTestD](), "First", "", "Second", "First"}},
332332
}
333333

334334
func TestUnmarshalBadPaths(t *testing.T) {

webdav/internal/xml/typeinfo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const (
4444
var tinfoMap = make(map[reflect.Type]*typeInfo)
4545
var tinfoLock sync.RWMutex
4646

47-
var nameType = reflect.TypeOf(Name{})
47+
var nameType = reflect.TypeFor[Name]()
4848

4949
// getTypeInfo returns the typeInfo structure with details necessary
5050
// for marshalling and unmarshalling typ.

0 commit comments

Comments
 (0)