Skip to content

x/tools/go/packages: "conflicting information" error when importing internal or main package #36188

@jayconrod

Description

@jayconrod

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.ToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions