Repository navigation
fix: keep delegates to same-named contracts distinct - #7
Conversation
There was a problem hiding this comment.
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
needsContractby the per-file-uniquequalifierand derive the injected alias as__mappergenContract${qualifier}, carrying theexportedname through to the emittedimport { exported as alias }statement. - Thread a new
qualifierparameter throughreferenceContractand update both call sites (type-only import usessymbol.nameasexported; name-lookup uses the qualifier asexported). - 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.
No description provided.