diff options
author | Ian Lance Taylor <iant@golang.org> | 2023-07-31 15:24:18 -0700 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2023-08-01 14:30:25 +0000 |
commit | 64c2072a94281fe5b19f9349b522881751347726 (patch) | |
tree | b7cbe09ffcda71166287e8b6e9ef201d7aec6e81 /src/html | |
parent | 56d3e84bb0195913e1d932d6fe8251047091076b (diff) | |
download | go-64c2072a94281fe5b19f9349b522881751347726.tar.gz go-64c2072a94281fe5b19f9349b522881751347726.zip |
text/template, html/template: use reflect.TypeFor for known types
For #60088
Change-Id: Ibc3983ca5cfe396087ddfa96c43cfe32ca47129a
Reviewed-on: https://go-review.googlesource.com/c/go/+/514640
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Daniel Martà <mvdan@mvdan.cc>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Diffstat (limited to 'src/html')
-rw-r--r-- | src/html/template/content.go | 4 | ||||
-rw-r--r-- | src/html/template/exec_test.go | 4 | ||||
-rw-r--r-- | src/html/template/js.go | 2 |
3 files changed, 5 insertions, 5 deletions
diff --git a/src/html/template/content.go b/src/html/template/content.go index 49d2f261af..6a9eb4e3cb 100644 --- a/src/html/template/content.go +++ b/src/html/template/content.go @@ -128,8 +128,8 @@ func indirect(a any) any { } var ( - errorType = reflect.TypeOf((*error)(nil)).Elem() - fmtStringerType = reflect.TypeOf((*fmt.Stringer)(nil)).Elem() + errorType = reflect.TypeFor[error]() + fmtStringerType = reflect.TypeFor[fmt.Stringer]() ) // indirectToStringerOrError returns the value, after dereferencing as many times diff --git a/src/html/template/exec_test.go b/src/html/template/exec_test.go index 51923ff9c7..05302156e0 100644 --- a/src/html/template/exec_test.go +++ b/src/html/template/exec_test.go @@ -268,8 +268,8 @@ type execTest struct { // of the max int boundary. // We do it this way so the test doesn't depend on ints being 32 bits. var ( - bigInt = fmt.Sprintf("0x%x", int(1<<uint(reflect.TypeOf(0).Bits()-1)-1)) - bigUint = fmt.Sprintf("0x%x", uint(1<<uint(reflect.TypeOf(0).Bits()-1))) + bigInt = fmt.Sprintf("0x%x", int(1<<uint(reflect.TypeFor[int]().Bits()-1)-1)) + bigUint = fmt.Sprintf("0x%x", uint(1<<uint(reflect.TypeFor[int]().Bits()-1))) ) var execTests = []execTest{ diff --git a/src/html/template/js.go b/src/html/template/js.go index 4e05c14557..717de4300c 100644 --- a/src/html/template/js.go +++ b/src/html/template/js.go @@ -124,7 +124,7 @@ var regexpPrecederKeywords = map[string]bool{ "void": true, } -var jsonMarshalType = reflect.TypeOf((*json.Marshaler)(nil)).Elem() +var jsonMarshalType = reflect.TypeFor[json.Marshaler]() // indirectToJSONMarshaler returns the value, after dereferencing as many times // as necessary to reach the base type (or nil) or an implementation of json.Marshal. |