Skip to content

Commit d005ca5

Browse files
committed
cmd/go/internal/vet: print line numbers appropriately on list errors
Fixes #36173 For reasons that are unclear to me, this commit: 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.
1 parent 753d56d commit d005ca5

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

src/cmd/go/internal/load/test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ func TestPackagesFor(p *Package, cover *TestCover) (pmain, ptest, pxtest *Packag
5454
break
5555
}
5656
if len(p1.DepsErrors) > 0 {
57-
perr := p1.DepsErrors[0]
58-
perr.Pos = "" // show full import stack
59-
err = perr
57+
err = p1.DepsErrors[0]
6058
break
6159
}
6260
}

src/cmd/go/internal/test/test.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,12 +728,16 @@ func runTest(cmd *base.Command, args []string) {
728728

729729
buildTest, runTest, printTest, err := builderTest(&b, p)
730730
if err != nil {
731-
str := err.Error()
732-
str = strings.TrimPrefix(str, "\n")
733731
if p.ImportPath != "" {
734-
base.Errorf("# %s\n%s", p.ImportPath, str)
732+
// Strip off line number info so we can show the full import stack.
733+
perr, ok := err.(*load.PackageError)
734+
if ok {
735+
perr.Pos = ""
736+
}
737+
738+
base.Errorf("# %s\n%s", p.ImportPath, strings.TrimPrefix(err.Error(), "\n"))
735739
} else {
736-
base.Errorf("%s", str)
740+
base.Errorf("%s", strings.TrimPrefix(err.Error(), "\n"))
737741
}
738742
fmt.Printf("FAIL\t%s [setup failed]\n", p.ImportPath)
739743
continue
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
env GO111MODULE=off
2+
3+
# Issue 36173. Verify that "go vet" prints line numbers on load errors.
4+
5+
! go vet a/a_test.go
6+
stderr 'a_test.go:4:3: use of internal package'
7+
8+
-- a/a.go --
9+
package a
10+
11+
-- a/a_test.go --
12+
package a
13+
14+
import (
15+
_ "a/x/internal/y"
16+
)
17+
18+
-- a/x/internal/y/y.go --
19+
package y

0 commit comments

Comments
 (0)