diff options
| author | Robert Findley <rfindley@google.com> | 2021-11-15 09:42:03 -0500 |
|---|---|---|
| committer | Robert Findley <rfindley@google.com> | 2021-11-16 15:59:43 +0000 |
| commit | 79d0013f53d4199b9f84d813221b71adf7eb1e4d (patch) | |
| tree | cca478dae811b7dd659389219cbcebe8f28eafe4 /src/cmd/compile/internal/noder | |
| parent | 7f4a946fa26f2ffdc14c354f2f1cc193ab5d0e90 (diff) | |
| download | go-79d0013f53d4199b9f84d813221b71adf7eb1e4d.tar.xz | |
go/types, types2: improve error messages referencing any
Because any is an a alias, it is naively formatted as interface{} in
error messages. This is a source of verbosity and potential confusion.
We can improve the situation by looking for pointer equality with the
any type. To avoid churn in the importers, do this all at once across
the compiler, go/types, and go/internal/gcimporter. CL 364194 makes the
corresponding change in x/tools/go/internal/gcimporter, allowing the
x/tools trybots to pass.
Fixes #49583
Change-Id: Ib59570937601308483f6273364cc59338f9b8b3b
Reviewed-on: https://go-review.googlesource.com/c/go/+/363974
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/noder')
| -rw-r--r-- | src/cmd/compile/internal/noder/types.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/cmd/compile/internal/noder/types.go b/src/cmd/compile/internal/noder/types.go index f035e0da97..fa24ab1844 100644 --- a/src/cmd/compile/internal/noder/types.go +++ b/src/cmd/compile/internal/noder/types.go @@ -26,6 +26,8 @@ func (g *irgen) pkg(pkg *types2.Package) *types.Pkg { return types.NewPkg(pkg.Path(), pkg.Name()) } +var universeAny = types2.Universe.Lookup("any").Type() + // typ converts a types2.Type to a types.Type, including caching of previously // translated types. func (g *irgen) typ(typ types2.Type) *types.Type { @@ -53,6 +55,12 @@ func (g *irgen) typ(typ types2.Type) *types.Type { // constructed part of a recursive type. Should not be called from outside this // file (g.typ is the "external" entry point). func (g *irgen) typ1(typ types2.Type) *types.Type { + // See issue 49583: the type checker has trouble keeping track of aliases, + // but for such a common alias as any we can improve things by preserving a + // pointer identity that can be checked when formatting type strings. + if typ == universeAny { + return types.AnyType + } // Cache type2-to-type mappings. Important so that each defined generic // type (instantiated or not) has a single types.Type representation. // Also saves a lot of computation and memory by avoiding re-translating |
