Open
Description
Reproducer:
package main
import (
"log"
"golang.org/x/tools/go/packages"
)
func main() {
pkgs, err := packages.Load(&packages.Config{
Mode: packages.LoadSyntax,
}, "module/pkg")
if err != nil {
log.Fatal(err)
}
packages.PrintErrors(pkgs)
}
module/pkg
package contains a file, that has a syntax error.
package pkg
func a() {
var a
}
$ go run .
-: # module/pkg
pkg/invalid.go:4:7: syntax error: unexpected newline, expected type
/home/mateusz/tmp/module/pkg/invalid.go:4:7: expected type, found newline
/home/mateusz/tmp/module/pkg/invalid.go:4:6: declared and not used: a
This happens in two cases, when NeedDeps
is not specified or NeedExportFile
is set. In such cases the -export=true
is passed to go list
. That in turn causes it to return an error, which ends up being stored in Package.Errors
with Kind == ListError
. go/packages
additionally parses the files, that go list returned, and it append them to Package.Errors
, thus we end up with duplicated errors.