Skip to content

fix: keep delegates to same-named contracts distinct - #7

Merged
Hoegsgaard merged 1 commit into
mainfrom
feat/delegate-without-import
Oct 4, 2026
Merged

Hoegsgaard merged 1 commit into
mainfrom
feat/delegate-without-import

Conversation

@Hoegsgaard

Copy link
Copy Markdown
Owner

No description provided.

Copilot AI balanced review requested due to automatic review settings October 4, 2026 22:06

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🔵 Needs a closer look

The change is a correct and well-tested code-generation fix, but code generation is a sensitive area where subtle aliasing regressions warrant a final human sign-off.

Review effort: Balanced
Findings: None

What changed in this PR

This PR fixes a code-generation bug in mappergen where two @mapper contracts that happen to share the same class name (e.g. UserMapping exported from two different files) could be conflated when a delegating mapper referenced both. The generator self-imports type-only delegate contracts, and the needsContract map was keyed by the contract's exported name with an alias of __mappergen${exported}. Since two distinct contracts can share an exported name, the second import overwrote the first, so both delegates resolved to the same contract. The fix re-keys on the qualifier (the local reference name, which is unique within the delegating file) and stores the exported name separately so the correct import statement is still emitted.

Changes:

  • Re-key needsContract by the per-file-unique qualifier and derive the injected alias as __mappergenContract${qualifier}, carrying the exported name through to the emitted import { exported as alias } statement.
  • Thread a new qualifier parameter through referenceContract and update both call sites (type-only import uses symbol.name as exported; name-lookup uses the qualifier as exported).
  • Add a regression test asserting that two same-named contracts delegated from one mapper produce instances of the correct, distinct classes.
File Description
src/​generate.ts Keys injected contract imports by the file-unique qualifier and emits aliases that keep same-named contracts distinct.
test/​generate.test.ts Adds a regression test proving two same-named contracts are delegated to separately via instanceof checks.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@Hoegsgaard
Hoegsgaard merged commit 8ccef65 into main Oct 4, 2026
9 checks passed
@Hoegsgaard
Hoegsgaard deleted the feat/delegate-without-import branch October 4, 2026 22:24
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.

2 participants