From: Rob Findley Date: Tue, 9 Mar 2021 19:22:38 +0000 (-0500) Subject: go/types: improve the positioning of broken import errors X-Git-Tag: go1.17beta1~1214 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=142a76530cf610fe02d151727fa0d8038c552127;p=gostls13.git go/types: improve the positioning of broken import errors The heuristic gopls uses to guess error spans can get tripped-up on certain valid characters in an import path (for example '-'). Update the error for broken imports to capture the full import path span, so that gopls doesn't need to rely on heuristics. Change-Id: Ieb8e0dce11933643f701b32271ff5f3477fecaaa Reviewed-on: https://go-review.googlesource.com/c/go/+/300169 Trust: Robert Findley Run-TryBot: Robert Findley TryBot-Result: Go Bot Reviewed-by: Robert Griesemer --- diff --git a/src/go/types/resolver.go b/src/go/types/resolver.go index 763ea48d38..8e67237446 100644 --- a/src/go/types/resolver.go +++ b/src/go/types/resolver.go @@ -130,7 +130,7 @@ func (check *Checker) filename(fileNo int) string { return fmt.Sprintf("file[%d]", fileNo) } -func (check *Checker) importPackage(pos token.Pos, path, dir string) *Package { +func (check *Checker) importPackage(at positioner, path, dir string) *Package { // If we already have a package for the given (path, dir) // pair, use it instead of doing a full import. // Checker.impMap only caches packages that are marked Complete @@ -170,7 +170,7 @@ func (check *Checker) importPackage(pos token.Pos, path, dir string) *Package { imp = nil // create fake package below } if err != nil { - check.errorf(atPos(pos), _BrokenImport, "could not import %s (%s)", path, err) + check.errorf(at, _BrokenImport, "could not import %s (%s)", path, err) if imp == nil { // create a new fake package // come up with a sensible package name (heuristic) @@ -254,7 +254,7 @@ func (check *Checker) collectObjects() { return } - imp := check.importPackage(d.spec.Path.Pos(), path, fileDir) + imp := check.importPackage(d.spec.Path, path, fileDir) if imp == nil { return }