Skip to content

cmd/go: go list has confusing/inconsistent semantics for Match and DepOnly #60794

@aclements

Description

@aclements

What version of Go are you using (go version)?

$ go version
go version go1.20.5 linux/amd64

(Also reproduced at HEAD.)

Does this issue reproduce with the latest release?

Yes.

What did you do?

$ cd $GOROOT/src
$ go list -deps -test -f '{{.ImportPath}} {{.DepOnly}} {{.Match}}' ./... | grep 'context\.test'
context [context.test] false [./...]
runtime/trace [context.test] true [./...]
testing [context.test] true [./...]
os/exec [context.test] true [./...]
internal/fuzz [context.test] true [./...]
os/signal [context.test] true [./...]
runtime/pprof [context.test] true [./...]
testing/internal/testdeps [context.test] true [./...]
net [context.test] true [./...]
context_test [context.test] false []
context.test false []

What did you expect to see?

The documentation for DepOnly and Match is:

        Match          []string // command-line patterns matching this package
        DepOnly        bool     // package is only a dependency, not explicitly listed

It's not clear whether packages built on behalf of tests "match" the pattern, but the output seems clearly inconsistent in some ways:

  1. Given that context.test has DepOnly == false, that implies cmd/go does think of context.test as "explicitly listed" by ./.... It also clearly thinks of, say, net as "explicitly listed" by ./.... So it seems odd that net [context.test] (and several others) have DepOnly == true, indicating that they're not "explicitly listed".
  2. Based on the documentation, I would expect that, if DepOnly == true, then it's "not explicitly listed", so Match should be empty because it didn't match any patterns. And if DepOnly == false, then it is "explicitly listed", and Match should list at least one pattern. For example, context.test is "explicitly listed", yet cmd/go can't tell me what pattern it matched.

What did you see instead?

DepOnly is true for some of these and false for others in ways I can't rationalize.

For some packages, DepOnly == true, but a Match pattern is also listed.

For some packages, DepOnly == false, but a Match pattern is listed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    GoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions