aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2023-01-11 16:43:11 -0800
committerGopher Robot <gobot@golang.org>2023-01-17 19:56:12 +0000
commit2f5718a80bdbc3d09a03a2bd21181945df040e24 (patch)
treeb9150b1c19d888ddbf98fa618c6259490347be15
parent4cc8d0eea93a83e36ad68e655d770f53d16253fd (diff)
downloadgo-2f5718a80bdbc3d09a03a2bd21181945df040e24.tar.xz
go/types: generate unify.go
Change-Id: If94a4c18e954ff403892d0a70e424ab58e997451 Reviewed-on: https://go-review.googlesource.com/c/go/+/461603 Reviewed-by: Robert Griesemer <gri@google.com> Run-TryBot: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com>
-rw-r--r--src/go/types/generator.go30
-rw-r--r--src/go/types/unify.go2
2 files changed, 32 insertions, 0 deletions
diff --git a/src/go/types/generator.go b/src/go/types/generator.go
index 2972f5e1bf..3f2668028d 100644
--- a/src/go/types/generator.go
+++ b/src/go/types/generator.go
@@ -115,6 +115,7 @@ var filemap = map[string]action{
"typeterm_test.go": nil,
"typeterm.go": nil,
"under.go": nil,
+ "unify.go": fixSprintf,
"universe.go": fixGlobalTypVarDecl,
"validtype.go": nil,
}
@@ -210,3 +211,32 @@ func fixGlobalTypVarDecl(f *ast.File) {
return true
})
}
+
+// fixSprintf adds an extra nil argument for the *token.FileSet parameter in sprintf calls.
+func fixSprintf(f *ast.File) {
+ ast.Inspect(f, func(n ast.Node) bool {
+ switch n := n.(type) {
+ case *ast.CallExpr:
+ if fun, _ := n.Fun.(*ast.Ident); fun != nil && fun.Name == "sprintf" && len(n.Args) >= 4 /* ... args */ {
+ n.Args = insert(n.Args, 1, newIdent(n.Args[1].Pos(), "nil"))
+ return false
+ }
+ }
+ return true
+ })
+}
+
+// newIdent returns a new identifier with the given position and name.
+func newIdent(pos token.Pos, name string) *ast.Ident {
+ id := ast.NewIdent(name)
+ id.NamePos = pos
+ return id
+}
+
+// insert inserts x at list[at] and moves the remaining elements up.
+func insert(list []ast.Expr, at int, x ast.Expr) []ast.Expr {
+ list = append(list, nil)
+ copy(list[at+1:], list[at:])
+ list[at] = x
+ return list
+}
diff --git a/src/go/types/unify.go b/src/go/types/unify.go
index 602e304b4a..58f2eedf8a 100644
--- a/src/go/types/unify.go
+++ b/src/go/types/unify.go
@@ -1,3 +1,5 @@
+// Code generated by "go run generator.go"; DO NOT EDIT.
+
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.