cmd/go: list includes "C" in the Imports field but not in Deps #60453
Labels
GoCommand
cmd/go
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Note how
runtime/cgo
includesC
in itsImports
field, but not in itsDeps
field. 1.20 is the same in this regard:The docs say:
So I always naively assumed
Imports
to be a strict subset ofDeps
, since one is the set of direct imports, and the other is the set of all direct and indirect package dependencies (transitive imports). However,C
breaks this rule.I think
Imports
should stop includingC
, and here are my reasons why:Imports
is not the list of direct dependencies, compared to the list of all transitive dependencies inDeps
, then how do I get the list of direct dependencies? Right now I'm takingImports
and removingC
from it, which feels hacky.C
is not truly a Go package nor a useful import path; see howgo list C
fails in a funky way (which arguably could be fixed to give a better error, too).CgoFiles
field, which is clearer and more directly useful.Deps
never included it either, so that's some proof that it's not really needed as a package dependency.The only reason why one could argue that
Imports
should includeC
is that there really is animport "C"
in the source code. However,Imports
is not a direct representation of the import declarations in the source code; they are deduplicated, sorted, and omit any renames likeimport foo "bar"
orimport _ "baz"
.The text was updated successfully, but these errors were encountered: