diff options
author | Robert Griesemer <gri@golang.org> | 2021-04-27 12:54:39 -0700 |
---|---|---|
committer | Robert Griesemer <gri@golang.org> | 2021-04-28 18:50:47 +0000 |
commit | 42812a2feec29873aa6ee594d1355948e78e92a3 (patch) | |
tree | 7190cce25a66fca0f722437511d4aba70a57027c /src/cmd/compile/internal/types2/check.go | |
parent | ea65a12f895ce67ee6fd843b9cee97d42f6ad0b4 (diff) | |
download | go-42812a2feec29873aa6ee594d1355948e78e92a3.tar.gz go-42812a2feec29873aa6ee594d1355948e78e92a3.zip |
types2: disambiguate package qualifiers in error messages
This is a port of the go/types CL https://golang.org/cl/313035
with minor adjustments (use of package syntax rather than go/ast).
Change-Id: I89410efb3d27be85fdbe827f966c2c91ee5693b5
Reviewed-on: https://go-review.googlesource.com/c/go/+/314410
Trust: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Diffstat (limited to 'src/cmd/compile/internal/types2/check.go')
-rw-r--r-- | src/cmd/compile/internal/types2/check.go | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/cmd/compile/internal/types2/check.go b/src/cmd/compile/internal/types2/check.go index c8ca118c3c..8d6cd1edab 100644 --- a/src/cmd/compile/internal/types2/check.go +++ b/src/cmd/compile/internal/types2/check.go @@ -87,7 +87,16 @@ type Checker struct { impMap map[importKey]*Package // maps (import path, source directory) to (complete or fake) package posMap map[*Interface][]syntax.Pos // maps interface types to lists of embedded interface positions typMap map[string]*Named // maps an instantiated named type hash to a *Named type - pkgCnt map[string]int // counts number of imported packages with a given name (for better error messages) + + // pkgPathMap maps package names to the set of distinct import paths we've + // seen for that name, anywhere in the import graph. It is used for + // disambiguating package names in error messages. + // + // pkgPathMap is allocated lazily, so that we don't pay the price of building + // it on the happy path. seenPkgMap tracks the packages that we've already + // walked. + pkgPathMap map[string]map[string]bool + seenPkgMap map[*Package]bool // information collected during type-checking of a set of package files // (initialized by Files, valid only for the duration of check.Files; @@ -181,7 +190,6 @@ func NewChecker(conf *Config, pkg *Package, info *Info) *Checker { impMap: make(map[importKey]*Package), posMap: make(map[*Interface][]syntax.Pos), typMap: make(map[string]*Named), - pkgCnt: make(map[string]int), } } @@ -271,9 +279,6 @@ func (check *Checker) checkFiles(files []*syntax.File) (err error) { print("== unusedImports ==") check.unusedImports() } - // no longer needed - release memory - check.imports = nil - check.dotImportMap = nil print("== recordUntyped ==") check.recordUntyped() @@ -285,6 +290,12 @@ func (check *Checker) checkFiles(files []*syntax.File) (err error) { check.pkg.complete = true + // no longer needed - release memory + check.imports = nil + check.dotImportMap = nil + check.pkgPathMap = nil + check.seenPkgMap = nil + // TODO(gri) There's more memory we should release at this point. return |