fix: suppress false E609 for builtin ADTs shared across imported modules#409
Conversation
Every CodeGenerator registers Option, Result, Ordering, UrlParts, Tuple, MdInline, and MdBlock via _register_builtin_adts(). When two modules are imported, the collision detector in _register_modules saw these types in both modules' _adt_layouts and emitted spurious E609 errors, preventing any program that imports from two different modules from running. Fix: call _register_builtin_adts() at the start of _register_modules to snapshot the builtin set, then skip those names in the ADT collision detection loop. User-defined ADT collisions (e.g. two modules both defining 'Color') still produce E609 correctly. Adds regression test and updates TESTING.md counts. Fixes #360. Co-Authored-By: Claude <noreply@anthropic.invalid>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughPre-registers builtin prelude ADT names and skips them when harvesting ADT layouts from imported modules to avoid duplicate-prelude collision diagnostics (E609/E610). Adds a regression test and updates testing docs and KNOWN_ISSUES accordingly. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested labels
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #409 +/- ##
=======================================
Coverage 90.30% 90.30%
=======================================
Files 49 49
Lines 19100 19104 +4
Branches 220 220
=======================================
+ Hits 17248 17252 +4
Misses 1848 1848
Partials 4 4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/test_codegen_modules.py`:
- Around line 453-479: Test test_prelude_types_not_flagged_as_collision
currently never references builtin ADTs, so strengthen it by changing the mod_a
and mod_b module source strings passed to self._resolved so they explicitly use
a builtin ADT (e.g., Option or Result) in the function signature or return
value; update the two _resolved calls for "mod_a" and "mod_b" used in
test_prelude_types_not_flagged_as_collision to declare/return or consume
Option/Result (so CodeGenerator._register_builtin_adts() initialization is
exercised when layouts for those ADTs are actually used), leaving the rest of
the test assertions intact.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 751f7ceb-be8b-452d-8001-4a1616312fd8
📒 Files selected for processing (3)
TESTING.mdtests/test_codegen_modules.pyvera/codegen/modules.py
Duplicate prelude types across imported modules (E609) is resolved by the _register_builtin_adts() pre-seeding in _register_modules. Co-Authored-By: Claude <noreply@anthropic.invalid>
…gnatures Modules now explicitly return @option<Int> so that the builtin ADT layouts appear in each temp CodeGenerator — more clearly demonstrating the exact scenario that triggered the false positive (builtin ADTs showing up in two imported module layouts and being mistaken for user-defined collisions). Co-Authored-By: Claude <noreply@anthropic.invalid>
Fixes #360.
Root cause
Every
CodeGeneratorregistersOption,Result,Ordering,UrlParts,Tuple,MdInline, andMdBlockvia_register_builtin_adts()— these are global infrastructure, not owned by any particular module. The collision detector in_register_modulesiterated over each temp generator's_adt_layoutsand attributed these builtins to whichever module was processed first. When a second module was processed, those same names appeared again and triggered E609.Fix
Call
self._register_builtin_adts()at the start of_register_modulesto snapshot the set of builtin ADT names, then skip those names entirely in the ADT collision detection loop. User-defined ADT collisions (two modules both defining their ownColortype) still produce E609 correctly — only the pre-registered builtins are exempted.Test plan
vera run examples/modules.vera --fn clamp -- 100 0 42returns 42 (was E609 × 7)test_prelude_types_not_flagged_as_collisionadded toTestNameCollisionDetectionGenerated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests
Documentation