]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types: improve the positioning of broken import errors
authorRob Findley <rfindley@google.com>
Tue, 9 Mar 2021 19:22:38 +0000 (14:22 -0500)
committerRobert Findley <rfindley@google.com>
Tue, 9 Mar 2021 22:00:50 +0000 (22:00 +0000)
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 <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/resolver.go

index 763ea48d38250ffbc4db7f0534088a88f3a1a80c..8e67237446bd44017950bbeb0a78fe6b8bc78546 100644 (file)
@@ -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
                                }