Skip to content

Commit

Permalink
cmd/go/internal/vet: print line numbers appropriately on list errors
Browse files Browse the repository at this point in the history
Fixes golang#36173

For reasons that are unclear to me, this commit:
golang@f1d5ce0
introduces a TestPackagesFor function that strips line numbers from error
messages. This commit introduces a new version of that function for 'go vet'
that always keeps the line numbers.
  • Loading branch information
nicks committed Feb 4, 2020
1 parent 753d56d commit 3578b2f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/cmd/go/internal/load/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,15 @@ func TestPackagesFor(p *Package, cover *TestCover) (pmain, ptest, pxtest *Packag
}
if len(p1.DepsErrors) > 0 {
perr := p1.DepsErrors[0]
perr.Pos = "" // show full import stack
// A typical ImportStack looks like
// [ "command-line-arguments", "(test)", "real/pkg/name" ]
// so we want to look at index 2 to see if the error is in the package
// we're looking at directly.
direct := len(perr.ImportStack) <= 2 ||
len(perr.ImportStack) == 3 && perr.ImportStack[2] == p1.ImportPath
if !direct {
perr.Pos = "" // show full import stack
}
err = perr
break
}
Expand Down
19 changes: 19 additions & 0 deletions src/cmd/go/testdata/script/vet_internal.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
env GO111MODULE=off

# Issue 36173. Verify that "go vet" prints line numbers on load errors.

! go vet a/a_test.go
stderr 'a_test.go:4:3: use of internal package'

-- a/a.go --
package a

-- a/a_test.go --
package a

import (
_ "a/x/internal/y"
)

-- a/x/internal/y/y.go --
package y

0 comments on commit 3578b2f

Please sign in to comment.