Skip to content

Go: imports of multi-file packages are dropped from --deps and --importers #191

Description

@JordanCoin

Summary

In a Go module, an import of a package that has two or more non-test .go files produces no edge. --deps lists every file in that package as standalone. --importers <file> says "No files import" and reports Coverage: complete. Imports of packages with exactly one non-test file resolve correctly.

Minimal repro

go.mod           module example.com/demo
single/single.go package single    (1 file)
single2/impl.go  package single2   (1 file, name differs from package)
multi/a.go       package multi     (2 files)
multi/b.go
named/named.go   package named     (2 files, one named after the package)
named/other.go
app/main.go      imports all four packages and calls into each

go build ./... succeeds.

$ codemap --deps .
  main ───▶ single/single, single2/impl
  +2 standalone files      # multi
  +2 standalone files      # named
7 files · 7 functions · 2 deps

$ codemap --importers multi/a.go .
No files import multi/a.go.
   Note: files in the same package never import each other ...
Coverage: complete

It's the same for multi/b.go, named/named.go and named/other.go. single2/impl.go resolves, so the file name doesn't matter. The only thing that decides it is the file count.

Same on this repo (v4.5.1)

$ grep -rl '"codemap/watch"' . | grep '\.go$' | grep -v '^./watch/' | wc -l
21
$ codemap --importers watch/events.go .
No files import watch/events.go.

analysis/contracts.go resolves (30 importers), because analysis/ has a single non-test file.

Impact

  • Hub detection, blast radius and --importers undercount any package split across files, which is most real Go packages.
  • The false negative is presented as complete coverage. "No files import X" is exactly the answer a caller acts on when deciding whether something is safe to change or delete.

Expected

An import of example.com/demo/multi links the importer to every non-test file in multi/, or to a package node that --importers expands. Either way, --importers multi/a.go lists app/main.go.

Related

#138 part 1 attributes "No files import" on Go files to same-package references not being modeled. This is a separate and larger gap: cross-package importers are also missed whenever the target package has more than one file.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions