aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2023-01-18 14:39:20 -0800
committerGopher Robot <gobot@golang.org>2023-01-20 18:12:57 +0000
commit2507e7897ba17bb33759c1c496d05bb7d459a31d (patch)
tree81a7409ffee76d476fb5d94be08480a54f9d6504
parent1011ccad5cdc7a90c31f07196df0f40ba2d5f6c5 (diff)
downloadgo-2507e7897ba17bb33759c1c496d05bb7d459a31d.tar.xz
go/types: provision for generating initorder.go, but disabled for now
Add the code to generate initorder.go but do not enable the generation of that file for now because the generated use uses error_ which has implications for gopls use (error_ produces a single error instead of pultiple \t-indented follow-on errors). Change-Id: I5cd8acdeb8845dbb4716f19cf90d88191dd4216c Reviewed-on: https://go-review.googlesource.com/c/go/+/461692 Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Robert Griesemer <gri@google.com>
-rw-r--r--src/go/types/generator.go42
1 files changed, 34 insertions, 8 deletions
diff --git a/src/go/types/generator.go b/src/go/types/generator.go
index 2a0b9e5d5c..be599443eb 100644
--- a/src/go/types/generator.go
+++ b/src/go/types/generator.go
@@ -83,14 +83,15 @@ func generate(filename string, action action) {
type action func(in *ast.File)
var filemap = map[string]action{
- "array.go": nil,
- "basic.go": nil,
- "chan.go": nil,
- "context.go": nil,
- "context_test.go": nil,
- "gccgosizes.go": nil,
- "hilbert_test.go": nil,
- "infer.go": func(f *ast.File) { fixTokenPos(f); fixInferSig(f) },
+ "array.go": nil,
+ "basic.go": nil,
+ "chan.go": nil,
+ "context.go": nil,
+ "context_test.go": nil,
+ "gccgosizes.go": nil,
+ "hilbert_test.go": nil,
+ "infer.go": func(f *ast.File) { fixTokenPos(f); fixInferSig(f) },
+ // "initorder.go": fixErrorfCall, // disabled for now due to unresolved error_ use implications for gopls
"instantiate_test.go": func(f *ast.File) { renameImportPath(f, `"cmd/compile/internal/types2"`, `"go/types"`) },
"lookup.go": nil,
"main_test.go": nil,
@@ -228,6 +229,31 @@ func fixInferSig(f *ast.File) {
})
}
+// fixErrorfCall updates calls of the form err.errorf(obj, ...) to err.errorf(obj.Pos(), ...).
+func fixErrorfCall(f *ast.File) {
+ ast.Inspect(f, func(n ast.Node) bool {
+ switch n := n.(type) {
+ case *ast.CallExpr:
+ if selx, _ := n.Fun.(*ast.SelectorExpr); selx != nil {
+ if ident, _ := selx.X.(*ast.Ident); ident != nil && ident.Name == "err" {
+ switch selx.Sel.Name {
+ case "errorf":
+ // rewrite err.errorf(obj, ... ) to err.errorf(obj.Pos(), ... )
+ if ident, _ := n.Args[0].(*ast.Ident); ident != nil && ident.Name == "obj" {
+ pos := n.Args[0].Pos()
+ fun := &ast.SelectorExpr{X: ident, Sel: newIdent(pos, "Pos")}
+ arg := &ast.CallExpr{Fun: fun, Lparen: pos, Args: nil, Ellipsis: token.NoPos, Rparen: pos}
+ n.Args[0] = arg
+ return false
+ }
+ }
+ }
+ }
+ }
+ return true
+ })
+}
+
// fixTraceSel renames uses of x.Trace to x.trace, where x for any x with a Trace field.
func fixTraceSel(f *ast.File) {
ast.Inspect(f, func(n ast.Node) bool {