]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: provision for generating initorder.go, but disabled for now
authorRobert Griesemer <gri@golang.org>
Wed, 18 Jan 2023 22:39:20 +0000 (14:39 -0800)
committerGopher Robot <gobot@golang.org>
Fri, 20 Jan 2023 18:12:57 +0000 (18:12 +0000)
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>

src/go/types/generator.go

index 2a0b9e5d5c15deb5295161c5a15dccd5d17cc59e..be599443eb4c0f6902a34b339e0530c26be5651a 100644 (file)
@@ -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 {