aboutsummaryrefslogtreecommitdiff
path: root/src/text
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2021-12-01 12:15:45 -0500
committerRuss Cox <rsc@golang.org>2021-12-13 18:45:54 +0000
commit2580d0e08d5e9f979b943758d3c49877fb2324cb (patch)
tree3aafccfd81087734156a1778ce2321adf345f271 /src/text
parent083ef5462494e81ee23316245c5d65085a3f62d9 (diff)
downloadgo-2580d0e08d5e9f979b943758d3c49877fb2324cb.tar.gz
go-2580d0e08d5e9f979b943758d3c49877fb2324cb.zip
all: gofmt -w -r 'interface{} -> any' src
And then revert the bootstrap cmd directories and certain testdata. And adjust tests as needed. Not reverting the changes in std that are bootstrapped, because some of those changes would appear in API docs, and we want to use any consistently. Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories when preparing the bootstrap copy. A few files changed as a result of running gofmt -w not because of interface{} -> any but because they hadn't been updated for the new //go:build lines. Fixes #49884. Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09 Reviewed-on: https://go-review.googlesource.com/c/go/+/368254 Trust: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/text')
-rw-r--r--src/text/scanner/scanner.go2
-rw-r--r--src/text/template/exec.go12
-rw-r--r--src/text/template/exec_test.go34
-rw-r--r--src/text/template/funcs.go10
-rw-r--r--src/text/template/parse/lex.go2
-rw-r--r--src/text/template/parse/parse.go12
-rw-r--r--src/text/template/parse/parse_test.go2
7 files changed, 37 insertions, 37 deletions
diff --git a/src/text/scanner/scanner.go b/src/text/scanner/scanner.go
index c5fc4ff93b..f1fbf9861d 100644
--- a/src/text/scanner/scanner.go
+++ b/src/text/scanner/scanner.go
@@ -340,7 +340,7 @@ func (s *Scanner) error(msg string) {
fmt.Fprintf(os.Stderr, "%s: %s\n", pos, msg)
}
-func (s *Scanner) errorf(format string, args ...interface{}) {
+func (s *Scanner) errorf(format string, args ...any) {
s.error(fmt.Sprintf(format, args...))
}
diff --git a/src/text/template/exec.go b/src/text/template/exec.go
index c42cbb2ad3..37984cf91a 100644
--- a/src/text/template/exec.go
+++ b/src/text/template/exec.go
@@ -126,7 +126,7 @@ func (e ExecError) Unwrap() error {
}
// errorf records an ExecError and terminates processing.
-func (s *state) errorf(format string, args ...interface{}) {
+func (s *state) errorf(format string, args ...any) {
name := doublePercent(s.tmpl.Name())
if s.node == nil {
format = fmt.Sprintf("template: %s: %s", name, format)
@@ -179,7 +179,7 @@ func errRecover(errp *error) {
// the output writer.
// A template may be executed safely in parallel, although if parallel
// executions share a Writer the output may be interleaved.
-func (t *Template) ExecuteTemplate(wr io.Writer, name string, data interface{}) error {
+func (t *Template) ExecuteTemplate(wr io.Writer, name string, data any) error {
tmpl := t.Lookup(name)
if tmpl == nil {
return fmt.Errorf("template: no template %q associated with template %q", name, t.name)
@@ -197,11 +197,11 @@ func (t *Template) ExecuteTemplate(wr io.Writer, name string, data interface{})
//
// If data is a reflect.Value, the template applies to the concrete
// value that the reflect.Value holds, as in fmt.Print.
-func (t *Template) Execute(wr io.Writer, data interface{}) error {
+func (t *Template) Execute(wr io.Writer, data any) error {
return t.execute(wr, data)
}
-func (t *Template) execute(wr io.Writer, data interface{}) (err error) {
+func (t *Template) execute(wr io.Writer, data any) (err error) {
defer errRecover(&err)
value, ok := data.(reflect.Value)
if !ok {
@@ -311,7 +311,7 @@ func (s *state) walkIfOrWith(typ parse.NodeType, dot reflect.Value, pipe *parse.
// IsTrue reports whether the value is 'true', in the sense of not the zero of its type,
// and whether the value has a meaningful truth value. This is the definition of
// truth used by if and other such actions.
-func IsTrue(val interface{}) (truth, ok bool) {
+func IsTrue(val any) (truth, ok bool) {
return isTrue(reflect.ValueOf(val))
}
@@ -1023,7 +1023,7 @@ func (s *state) printValue(n parse.Node, v reflect.Value) {
// printableValue returns the, possibly indirected, interface value inside v that
// is best for a call to formatted printer.
-func printableValue(v reflect.Value) (interface{}, bool) {
+func printableValue(v reflect.Value) (any, bool) {
if v.Kind() == reflect.Pointer {
v, _ = indirect(v) // fmt.Fprint handles nil.
}
diff --git a/src/text/template/exec_test.go b/src/text/template/exec_test.go
index 3c40aa901e..8c8143396d 100644
--- a/src/text/template/exec_test.go
+++ b/src/text/template/exec_test.go
@@ -46,7 +46,7 @@ type T struct {
MSI map[string]int
MSIone map[string]int // one element, for deterministic output
MSIEmpty map[string]int
- MXI map[interface{}]int
+ MXI map[any]int
MII map[int]int
MI32S map[int32]string
MI64S map[int64]string
@@ -56,11 +56,11 @@ type T struct {
MUI8S map[uint8]string
SMSI []map[string]int
// Empty interfaces; used to see if we can dig inside one.
- Empty0 interface{} // nil
- Empty1 interface{}
- Empty2 interface{}
- Empty3 interface{}
- Empty4 interface{}
+ Empty0 any // nil
+ Empty1 any
+ Empty2 any
+ Empty3 any
+ Empty4 any
// Non-empty interfaces.
NonEmptyInterface I
NonEmptyInterfacePtS *I
@@ -138,7 +138,7 @@ var tVal = &T{
SB: []bool{true, false},
MSI: map[string]int{"one": 1, "two": 2, "three": 3},
MSIone: map[string]int{"one": 1},
- MXI: map[interface{}]int{"one": 1},
+ MXI: map[any]int{"one": 1},
MII: map[int]int{1: 1},
MI32S: map[int32]string{1: "one", 2: "two"},
MI64S: map[int64]string{2: "i642", 3: "i643"},
@@ -209,7 +209,7 @@ func (t *T) Method2(a uint16, b string) string {
return fmt.Sprintf("Method2: %d %s", a, b)
}
-func (t *T) Method3(v interface{}) string {
+func (t *T) Method3(v any) string {
return fmt.Sprintf("Method3: %v", v)
}
@@ -249,7 +249,7 @@ func (u *U) TrueFalse(b bool) string {
return ""
}
-func typeOf(arg interface{}) string {
+func typeOf(arg any) string {
return fmt.Sprintf("%T", arg)
}
@@ -257,7 +257,7 @@ type execTest struct {
name string
input string
output string
- data interface{}
+ data any
ok bool
}
@@ -390,7 +390,7 @@ var execTests = []execTest{
{".VariadicFuncInt", "{{call .VariadicFuncInt 33 `he` `llo`}}", "33=<he+llo>", tVal, true},
{"if .BinaryFunc call", "{{ if .BinaryFunc}}{{call .BinaryFunc `1` `2`}}{{end}}", "[1=2]", tVal, true},
{"if not .BinaryFunc call", "{{ if not .BinaryFunc}}{{call .BinaryFunc `1` `2`}}{{else}}No{{end}}", "No", tVal, true},
- {"Interface Call", `{{stringer .S}}`, "foozle", map[string]interface{}{"S": bytes.NewBufferString("foozle")}, true},
+ {"Interface Call", `{{stringer .S}}`, "foozle", map[string]any{"S": bytes.NewBufferString("foozle")}, true},
{".ErrFunc", "{{call .ErrFunc}}", "bla", tVal, true},
{"call nil", "{{call nil}}", "", tVal, false},
@@ -748,7 +748,7 @@ func add(args ...int) int {
return sum
}
-func echo(arg interface{}) interface{} {
+func echo(arg any) any {
return arg
}
@@ -767,7 +767,7 @@ func stringer(s fmt.Stringer) string {
return s.String()
}
-func mapOfThree() interface{} {
+func mapOfThree() any {
return map[string]int{"three": 3}
}
@@ -1468,7 +1468,7 @@ func TestBlock(t *testing.T) {
func TestEvalFieldErrors(t *testing.T) {
tests := []struct {
name, src string
- value interface{}
+ value any
want string
}{
{
@@ -1611,7 +1611,7 @@ func TestInterfaceValues(t *testing.T) {
for _, tt := range tests {
tmpl := Must(New("tmpl").Parse(tt.text))
var buf bytes.Buffer
- err := tmpl.Execute(&buf, map[string]interface{}{
+ err := tmpl.Execute(&buf, map[string]any{
"PlusOne": func(n int) int {
return n + 1
},
@@ -1640,7 +1640,7 @@ func TestInterfaceValues(t *testing.T) {
// Check that panics during calls are recovered and returned as errors.
func TestExecutePanicDuringCall(t *testing.T) {
- funcs := map[string]interface{}{
+ funcs := map[string]any{
"doPanic": func() string {
panic("custom panic string")
},
@@ -1648,7 +1648,7 @@ func TestExecutePanicDuringCall(t *testing.T) {
tests := []struct {
name string
input string
- data interface{}
+ data any
wantErr string
}{
{
diff --git a/src/text/template/funcs.go b/src/text/template/funcs.go
index 11e2e903c8..dca5ed28db 100644
--- a/src/text/template/funcs.go
+++ b/src/text/template/funcs.go
@@ -31,7 +31,7 @@ import (
// apply to arguments of arbitrary type can use parameters of type interface{} or
// of type reflect.Value. Similarly, functions meant to return a result of arbitrary
// type can return interface{} or reflect.Value.
-type FuncMap map[string]interface{}
+type FuncMap map[string]any
// builtins returns the FuncMap.
// It is not a global variable so the linker can dead code eliminate
@@ -627,7 +627,7 @@ func HTMLEscapeString(s string) string {
// HTMLEscaper returns the escaped HTML equivalent of the textual
// representation of its arguments.
-func HTMLEscaper(args ...interface{}) string {
+func HTMLEscaper(args ...any) string {
return HTMLEscapeString(evalArgs(args))
}
@@ -718,13 +718,13 @@ func jsIsSpecial(r rune) bool {
// JSEscaper returns the escaped JavaScript equivalent of the textual
// representation of its arguments.
-func JSEscaper(args ...interface{}) string {
+func JSEscaper(args ...any) string {
return JSEscapeString(evalArgs(args))
}
// URLQueryEscaper returns the escaped value of the textual representation of
// its arguments in a form suitable for embedding in a URL query.
-func URLQueryEscaper(args ...interface{}) string {
+func URLQueryEscaper(args ...any) string {
return url.QueryEscape(evalArgs(args))
}
@@ -733,7 +733,7 @@ func URLQueryEscaper(args ...interface{}) string {
// except that each argument is indirected (if a pointer), as required,
// using the same rules as the default string evaluation during template
// execution.
-func evalArgs(args []interface{}) string {
+func evalArgs(args []any) string {
ok := false
var s string
// Fast path for simple common case.
diff --git a/src/text/template/parse/lex.go b/src/text/template/parse/lex.go
index 95e33771c0..40d0411121 100644
--- a/src/text/template/parse/lex.go
+++ b/src/text/template/parse/lex.go
@@ -190,7 +190,7 @@ func (l *lexer) acceptRun(valid string) {
// errorf returns an error token and terminates the scan by passing
// back a nil pointer that will be the next state, terminating l.nextItem.
-func (l *lexer) errorf(format string, args ...interface{}) stateFn {
+func (l *lexer) errorf(format string, args ...any) stateFn {
l.items <- item{itemError, l.start, fmt.Sprintf(format, args...), l.startLine}
return nil
}
diff --git a/src/text/template/parse/parse.go b/src/text/template/parse/parse.go
index 64b29a2e16..b0cbe9dfc8 100644
--- a/src/text/template/parse/parse.go
+++ b/src/text/template/parse/parse.go
@@ -24,7 +24,7 @@ type Tree struct {
Mode Mode // parsing mode.
text string // text parsed to create the template (or its parent)
// Parsing only; cleared after parse.
- funcs []map[string]interface{}
+ funcs []map[string]any
lex *lexer
token [3]item // three-token lookahead for parser.
peekCount int
@@ -59,7 +59,7 @@ func (t *Tree) Copy() *Tree {
// templates described in the argument string. The top-level template will be
// given the specified name. If an error is encountered, parsing stops and an
// empty map is returned with the error.
-func Parse(name, text, leftDelim, rightDelim string, funcs ...map[string]interface{}) (map[string]*Tree, error) {
+func Parse(name, text, leftDelim, rightDelim string, funcs ...map[string]any) (map[string]*Tree, error) {
treeSet := make(map[string]*Tree)
t := New(name)
t.text = text
@@ -128,7 +128,7 @@ func (t *Tree) peekNonSpace() item {
// Parsing.
// New allocates a new parse tree with the given name.
-func New(name string, funcs ...map[string]interface{}) *Tree {
+func New(name string, funcs ...map[string]any) *Tree {
return &Tree{
Name: name,
funcs: funcs,
@@ -158,7 +158,7 @@ func (t *Tree) ErrorContext(n Node) (location, context string) {
}
// errorf formats the error and terminates processing.
-func (t *Tree) errorf(format string, args ...interface{}) {
+func (t *Tree) errorf(format string, args ...any) {
t.Root = nil
format = fmt.Sprintf("template: %s:%d: %s", t.ParseName, t.token[0].line, format)
panic(fmt.Errorf(format, args...))
@@ -218,7 +218,7 @@ func (t *Tree) recover(errp *error) {
}
// startParse initializes the parser, using the lexer.
-func (t *Tree) startParse(funcs []map[string]interface{}, lex *lexer, treeSet map[string]*Tree) {
+func (t *Tree) startParse(funcs []map[string]any, lex *lexer, treeSet map[string]*Tree) {
t.Root = nil
t.lex = lex
t.vars = []string{"$"}
@@ -240,7 +240,7 @@ func (t *Tree) stopParse() {
// the template for execution. If either action delimiter string is empty, the
// default ("{{" or "}}") is used. Embedded template definitions are added to
// the treeSet map.
-func (t *Tree) Parse(text, leftDelim, rightDelim string, treeSet map[string]*Tree, funcs ...map[string]interface{}) (tree *Tree, err error) {
+func (t *Tree) Parse(text, leftDelim, rightDelim string, treeSet map[string]*Tree, funcs ...map[string]any) (tree *Tree, err error) {
defer t.recover(&err)
t.ParseName = t.Name
emitComment := t.Mode&ParseComments != 0
diff --git a/src/text/template/parse/parse_test.go b/src/text/template/parse/parse_test.go
index c3679a08de..0c4778c7b3 100644
--- a/src/text/template/parse/parse_test.go
+++ b/src/text/template/parse/parse_test.go
@@ -318,7 +318,7 @@ var parseTests = []parseTest{
{"block definition", `{{block "foo"}}hello{{end}}`, hasError, ""},
}
-var builtins = map[string]interface{}{
+var builtins = map[string]any{
"printf": fmt.Sprintf,
"contains": strings.Contains,
}