diff options
| author | Robert Griesemer <gri@golang.org> | 2023-01-18 14:59:04 -0800 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-01-20 18:12:59 +0000 |
| commit | e38cb25b331f59a6a5e1ec8527aac9964a45f567 (patch) | |
| tree | c7b8cfadfc0878bcaf2062aafd395cd0df7bfa4c | |
| parent | 2507e7897ba17bb33759c1c496d05bb7d459a31d (diff) | |
| download | go-e38cb25b331f59a6a5e1ec8527aac9964a45f567.tar.xz | |
go/types: generate instantiate.go
Change-Id: Iad8b78bbf52eb2b0de05471bfd5a5506dc45e055
Reviewed-on: https://go-review.googlesource.com/c/go/+/461693
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
| -rw-r--r-- | src/go/types/generator.go | 32 | ||||
| -rw-r--r-- | src/go/types/instantiate.go | 2 |
2 files changed, 31 insertions, 3 deletions
diff --git a/src/go/types/generator.go b/src/go/types/generator.go index be599443eb..fc6295d3c8 100644 --- a/src/go/types/generator.go +++ b/src/go/types/generator.go @@ -91,7 +91,8 @@ var filemap = map[string]action{ "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 + // "initorder.go": fixErrErrorfCall, // disabled for now due to unresolved error_ use implications for gopls + "instantiate.go": func(f *ast.File) { fixTokenPos(f); fixCheckErrorfCall(f) }, "instantiate_test.go": func(f *ast.File) { renameImportPath(f, `"cmd/compile/internal/types2"`, `"go/types"`) }, "lookup.go": nil, "main_test.go": nil, @@ -229,8 +230,8 @@ func fixInferSig(f *ast.File) { }) } -// fixErrorfCall updates calls of the form err.errorf(obj, ...) to err.errorf(obj.Pos(), ...). -func fixErrorfCall(f *ast.File) { +// fixErrErrorfCall updates calls of the form err.errorf(obj, ...) to err.errorf(obj.Pos(), ...). +func fixErrErrorfCall(f *ast.File) { ast.Inspect(f, func(n ast.Node) bool { switch n := n.(type) { case *ast.CallExpr: @@ -254,6 +255,31 @@ func fixErrorfCall(f *ast.File) { }) } +// fixCheckErrorfCall updates calls of the form check.errorf(pos, ...) to check.errorf(atPos(pos), ...). +func fixCheckErrorfCall(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 == "check" { + switch selx.Sel.Name { + case "errorf": + // rewrite check.errorf(pos, ... ) to check.errorf(atPos(pos), ... ) + if ident, _ := n.Args[0].(*ast.Ident); ident != nil && ident.Name == "pos" { + pos := n.Args[0].Pos() + fun := newIdent(pos, "atPos") + arg := &ast.CallExpr{Fun: fun, Lparen: pos, Args: []ast.Expr{ident}, 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 { diff --git a/src/go/types/instantiate.go b/src/go/types/instantiate.go index 8509a31e35..726e84d7ab 100644 --- a/src/go/types/instantiate.go +++ b/src/go/types/instantiate.go @@ -1,3 +1,5 @@ +// Code generated by "go run generator.go"; DO NOT EDIT. + // Copyright 2021 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. |
