Skip to content

Fix package name collision when two packages share the same base name#111

Merged
shane-tw merged 2 commits intomasterfrom
fix/package-name-collision
May 5, 2026
Merged

Fix package name collision when two packages share the same base name#111
shane-tw merged 2 commits intomasterfrom
fix/package-name-collision

Conversation

@shane-tw
Copy link
Copy Markdown
Contributor

@shane-tw shane-tw commented May 5, 2026

Summary

  • When two packages share the same last path component (e.g. sub-a/shared and sub-b/shared), GetReference was computing the same lookup key (shared.Request) for both, causing the second definition to silently overwrite the first in prog.References.
  • Fix adds a collision check before storing: if the short key already exists for a different package, a numeric suffix is appended (shared.Request2, shared.Request3, …) to produce a unique key. Repeated calls for the same colliding package correctly reuse the existing suffixed key.
  • Adds a regression test with two sub-packages both named shared, verifying their definitions remain distinct in the generated output.

Test plan

  • go test ./... passes
  • New package-name-collision fixture confirms shared.Request and shared.Request2 resolve to the correct, separate struct definitions

🤖 Generated with Claude Code

When two packages have the same last path component (e.g. sub-a/shared
and sub-b/shared both resolve to "shared"), GetReference was using
filepath.Base(pkg) as the lookup key, causing the second type to
silently overwrite the first in prog.References.

The fix adds a collision check before storing: if the key already exists
for a different package, a numeric suffix is appended (shared.Request2,
shared.Request3, …) to produce a unique key. Repeated calls for the same
colliding package reuse the existing suffixed key.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@coveralls
Copy link
Copy Markdown

coveralls commented May 5, 2026

Coverage Report for CI Build 25377765942

Coverage decreased (-0.1%) to 53.04%

Details

  • Coverage decreased (-0.1%) from the base build.
  • Patch coverage: 36 uncovered changes across 1 file (11 of 47 lines covered, 23.4%).
  • 7 coverage regressions across 1 file.

Uncovered Changes

File Changed Covered %
docparse/find.go 47 11 23.4%

Coverage Regressions

7 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
docparse/find.go 7 51.02%

Coverage Stats

Coverage Status
Relevant Lines: 2204
Covered Lines: 1169
Line Coverage: 53.04%
Coverage Strength: 43.02 hits per line

💛 - Coveralls

…xity

GetReference exceeded the gocyclo threshold of 65 (was 68). Extracting the
field-whitelist processing block into its own helper brings it back under
the limit without changing behaviour.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@shane-tw shane-tw requested review from aodhom and twariel May 5, 2026 13:00
@shane-tw shane-tw merged commit d2532ec into master May 5, 2026
3 checks passed
@shane-tw shane-tw deleted the fix/package-name-collision branch May 5, 2026 13:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants