]> Cypherpunks repositories - gostls13.git/commitdiff
text/template, html/template: use reflect.TypeFor for known types
authorIan Lance Taylor <iant@golang.org>
Mon, 31 Jul 2023 22:24:18 +0000 (15:24 -0700)
committerGopher Robot <gobot@golang.org>
Tue, 1 Aug 2023 14:30:25 +0000 (14:30 +0000)
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>

src/html/template/content.go
src/html/template/exec_test.go
src/html/template/js.go
src/text/template/exec.go
src/text/template/exec_test.go

index 49d2f261af22f7e6a9417ed8ceff70f104c27986..6a9eb4e3cb7ca9be67b90a4e820679a0c55ce9e2 100644 (file)
@@ -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
index 51923ff9c7aee2b6aa839ad7c19f7ddbdda1cab4..05302156e0703390ef1460c000c132be74a29b9b 100644 (file)
@@ -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{
index 4e05c1455723f54d1cd259427f87d25c1670b4d3..717de4300cced40e0769eb42bea6fe9479be7d86 100644 (file)
@@ -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.
index fd7db657d38df0d0d9f1a86ecc9008ec00bb2994..2b778fff696fb3ed091235a7713b16be901ac526 100644 (file)
@@ -94,7 +94,7 @@ type missingValType struct{}
 
 var missingVal = reflect.ValueOf(missingValType{})
 
-var missingValReflectType = reflect.TypeOf(missingValType{})
+var missingValReflectType = reflect.TypeFor[missingValType]()
 
 func isMissing(v reflect.Value) bool {
        return v.IsValid() && v.Type() == missingValReflectType
@@ -708,9 +708,9 @@ func (s *state) evalField(dot reflect.Value, fieldName string, node parse.Node,
 }
 
 var (
-       errorType        = reflect.TypeOf((*error)(nil)).Elem()
-       fmtStringerType  = reflect.TypeOf((*fmt.Stringer)(nil)).Elem()
-       reflectValueType = reflect.TypeOf((*reflect.Value)(nil)).Elem()
+       errorType        = reflect.TypeFor[error]()
+       fmtStringerType  = reflect.TypeFor[fmt.Stringer]()
+       reflectValueType = reflect.TypeFor[reflect.Value]()
 )
 
 // evalCall executes a function or method call. If it's a method, fun already has the receiver bound, so
index 6eb0d41a5152cf7a477e20758e835b4ebe0c8398..e607fd3beea86bfbba5302a07f050e2907bc08a7 100644 (file)
@@ -265,8 +265,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{