-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Description
Suppose we have a module with two packages, a and b where a imports b. If b is a main package or is in an internal directory not visible to a, go list -e -deps -json a b
will report b twice: once as a dummy package containing an error for a's bad import, and again as the real b package.
As a concrete example:
-- a/a.go --
package a
import _ "example.com/m/b"
-- b/b.go --
package main
-- go.mod --
module example.com/m
go 1.13
The go list
command prints example.com/m/b
twice. This is working as intended (though perhaps not as expected).
$ go list -e -deps ./...
internal/cpu
unsafe
internal/bytealg
runtime/internal/atomic
runtime/internal/sys
runtime/internal/math
runtime
example.com/m/b
example.com/m/a
example.com/m/b
golang.org/x/tools/go/packages
gets confused by this.
$ gopackages ./a ./b
gopackages: internal error: go list gives conflicting information for package example.com/m/b
Internally, go/packages
runs go list
. If it sees a package more than once with different data, it reports this error.
These kinds of errors should have positions with file paths in the importing package. Perhaps go/packages
could figure out which package contains the file with the error, then attach the error to that package.
cc @matloob