From b93acc2126d5ad1a8836390a0fd801eb7dceb5b6 Mon Sep 17 00:00:00 2001 From: cuishuang Date: Sun, 5 Oct 2025 16:04:04 +0800 Subject: [PATCH] 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 Reviewed-by: Damien Neil Auto-Submit: Michael Pratt LUCI-TryBot-Result: Go LUCI --- http2/connframes_test.go | 2 +- webdav/internal/xml/marshal.go | 6 +++--- webdav/internal/xml/read.go | 6 +++--- webdav/internal/xml/read_test.go | 8 ++++---- webdav/internal/xml/typeinfo.go | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/http2/connframes_test.go b/http2/connframes_test.go index e3f8a96e..f2e6eb52 100644 --- a/http2/connframes_test.go +++ b/http2/connframes_test.go @@ -110,7 +110,7 @@ frame: if typ.Kind() != reflect.Func || typ.NumIn() != 1 || typ.NumOut() != 1 || - typ.Out(0) != reflect.TypeOf(true) { + typ.Out(0) != reflect.TypeFor[bool]() { tf.t.Fatalf("expected func(*SomeFrame) bool, got %T", f) } if typ.In(0) == reflect.TypeOf(fr) { diff --git a/webdav/internal/xml/marshal.go b/webdav/internal/xml/marshal.go index 4dd0f417..a0ec9cba 100644 --- a/webdav/internal/xml/marshal.go +++ b/webdav/internal/xml/marshal.go @@ -546,9 +546,9 @@ func (p *printer) setAttrPrefix(prefix, url string) { } var ( - marshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem() - marshalerAttrType = reflect.TypeOf((*MarshalerAttr)(nil)).Elem() - textMarshalerType = reflect.TypeOf((*encoding.TextMarshaler)(nil)).Elem() + marshalerType = reflect.TypeFor[Marshaler]() + marshalerAttrType = reflect.TypeFor[MarshalerAttr]() + textMarshalerType = reflect.TypeFor[encoding.TextMarshaler]() ) // marshalValue writes one or more XML elements representing val. diff --git a/webdav/internal/xml/read.go b/webdav/internal/xml/read.go index bfaef6f1..2ba3bb4a 100644 --- a/webdav/internal/xml/read.go +++ b/webdav/internal/xml/read.go @@ -262,9 +262,9 @@ func (p *Decoder) unmarshalAttr(val reflect.Value, attr Attr) error { } var ( - unmarshalerType = reflect.TypeOf((*Unmarshaler)(nil)).Elem() - unmarshalerAttrType = reflect.TypeOf((*UnmarshalerAttr)(nil)).Elem() - textUnmarshalerType = reflect.TypeOf((*encoding.TextUnmarshaler)(nil)).Elem() + unmarshalerType = reflect.TypeFor[Unmarshaler]() + unmarshalerAttrType = reflect.TypeFor[UnmarshalerAttr]() + textUnmarshalerType = reflect.TypeFor[encoding.TextUnmarshaler]() ) // Unmarshal a single XML element into val. diff --git a/webdav/internal/xml/read_test.go b/webdav/internal/xml/read_test.go index 02f1e10c..e587d11f 100644 --- a/webdav/internal/xml/read_test.go +++ b/webdav/internal/xml/read_test.go @@ -325,10 +325,10 @@ type BadPathEmbeddedB struct { var badPathTests = []struct { v, e interface{} }{ - {&BadPathTestA{}, &TagPathError{reflect.TypeOf(BadPathTestA{}), "First", "items>item1", "Second", "items"}}, - {&BadPathTestB{}, &TagPathError{reflect.TypeOf(BadPathTestB{}), "First", "items>item1", "Second", "items>item1>value"}}, - {&BadPathTestC{}, &TagPathError{reflect.TypeOf(BadPathTestC{}), "First", "", "Second", "First"}}, - {&BadPathTestD{}, &TagPathError{reflect.TypeOf(BadPathTestD{}), "First", "", "Second", "First"}}, + {&BadPathTestA{}, &TagPathError{reflect.TypeFor[BadPathTestA](), "First", "items>item1", "Second", "items"}}, + {&BadPathTestB{}, &TagPathError{reflect.TypeFor[BadPathTestB](), "First", "items>item1", "Second", "items>item1>value"}}, + {&BadPathTestC{}, &TagPathError{reflect.TypeFor[BadPathTestC](), "First", "", "Second", "First"}}, + {&BadPathTestD{}, &TagPathError{reflect.TypeFor[BadPathTestD](), "First", "", "Second", "First"}}, } func TestUnmarshalBadPaths(t *testing.T) { diff --git a/webdav/internal/xml/typeinfo.go b/webdav/internal/xml/typeinfo.go index 45cdfbb3..b0b0f55a 100644 --- a/webdav/internal/xml/typeinfo.go +++ b/webdav/internal/xml/typeinfo.go @@ -44,7 +44,7 @@ const ( var tinfoMap = make(map[reflect.Type]*typeInfo) var tinfoLock sync.RWMutex -var nameType = reflect.TypeOf(Name{}) +var nameType = reflect.TypeFor[Name]() // getTypeInfo returns the typeInfo structure with details necessary // for marshalling and unmarshalling typ.