fix(hir): static method calls + static field get/set must resolve scope-local class renames#5969
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (8)
📝 WalkthroughWalkthroughStatic member lowering now resolves scope-local class renames before class, field, and method lookups, and a regression test covers colliding class bindings. Release metadata was bumped to v0.5.1235. ChangesResolve renamed classes for static member access
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
crates/perry-hir/src/lower/expr_assign.rs (1)
502-536: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winResolve class renames in the
ClassName.prototypepath. This branch still uses the rawcls_name; a body-local renamedclass Xcan still resolve to the first same-named registrant. Applyctx.resolve_class_namehere before the class lookup /ProtoOwner::Classselection.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/perry-hir/src/lower/expr_assign.rs` around lines 502 - 536, The class-property assignment handling in expr_assign.rs still uses the raw class name in the ClassName.prototype path, so body-local renamed classes can bind to the wrong registrant. Update the logic around the member assignment/class lookup branch to call ctx.resolve_class_name on the object name before doing ctx.lookup_class and before choosing the ProtoOwner::Class target, matching the existing static-field rename handling used in the same function.
🧹 Nitpick comments (1)
crates/perry/tests/capture_rereg_renamed_class.rs (1)
186-233: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMissing coverage for the private-static-method arm.
The PR fixes four lookup arms including private static methods (
#helper()), but this test only exercises the public static method, static field get/set, and constructor arms. Consider adding astatic#helper()call to close out coverage for that arm too.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@crates/perry/tests/capture_rereg_renamed_class.rs` around lines 186 - 233, Add coverage for the private-static-method dispatch path in renamed_class_statics_dispatch_to_renamed_registrant by extending the test snippet to include a static private method like `#helper` on the renamed class e and verify it is invoked correctly. Keep the existing mkA/mkB structure, but exercise the private static method alongside the current public static method, static field, and constructor assertions so the renamed registrant lookup arm is covered.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Outside diff comments:
In `@crates/perry-hir/src/lower/expr_assign.rs`:
- Around line 502-536: The class-property assignment handling in expr_assign.rs
still uses the raw class name in the ClassName.prototype path, so body-local
renamed classes can bind to the wrong registrant. Update the logic around the
member assignment/class lookup branch to call ctx.resolve_class_name on the
object name before doing ctx.lookup_class and before choosing the
ProtoOwner::Class target, matching the existing static-field rename handling
used in the same function.
---
Nitpick comments:
In `@crates/perry/tests/capture_rereg_renamed_class.rs`:
- Around line 186-233: Add coverage for the private-static-method dispatch path
in renamed_class_statics_dispatch_to_renamed_registrant by extending the test
snippet to include a static private method like `#helper` on the renamed class e
and verify it is invoked correctly. Keep the existing mkA/mkB structure, but
exercise the private static method alongside the current public static method,
static field, and constructor assertions so the renamed registrant lookup arm is
covered.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 47ffdc70-125b-4b01-8da3-a551c5c7bad4
📒 Files selected for processing (5)
crates/perry-hir/src/lower/expr_assign.rscrates/perry-hir/src/lower/expr_call/static_and_instance.rscrates/perry-hir/src/lower/expr_member.rscrates/perry-hir/src/lower/lower_expr/assignment.rscrates/perry/tests/capture_rereg_renamed_class.rs
…cope-local class renames A body-local `class X` colliding with an outer/prior `class X` registers under a scope-local rename (class_renames), and bare-ident references (ClassRef) and `new X()` already resolve it — but the static-METHOD-call arm and the static-FIELD get/set arms looked the raw name up directly, so they bound the FIRST same-named registrant: factory B's `e.who()` dispatched to factory A's static and read A's capture snapshot (same_class_name_across_factories_keeps_snapshots_separate red on main: 'B: alpha' instead of 'B: beta1'). Resolve the rename before the class lookups in all four arms; imports keep the raw name (a renamed class is body-local by construction, never imported). Adds renamed_class_statics_dispatch_to_renamed_registrant covering static calls, static field reads/writes, and construction across two factories.
51ddb9d to
0d02e7d
Compare
Fixes the red acceptance test on main (
same_class_name_across_factories_keeps_snapshots_separate, from #5938): a body-localclass Xcolliding with an outer/priorclass Xregisters under a scope-local rename (class_renames), and bare-ident references +new X()already resolve it — but the static-METHOD-call arm (expr_call/static_and_instance.rs, both Ident and #private arms) and the static-FIELD get/set arms (expr_member.rs,expr_assign.rs,lower_expr/assignment.rs) looked up the raw name, binding the FIRST same-named registrant. Factory B'se.who()dispatched to factory A's static and read A's capture snapshot ('B: alpha' instead of 'B: beta1').All four arms now resolve the rename before the class lookups; imports keep the raw name (a renamed class is body-local by construction, never imported).
renamed_class_statics_dispatch_to_renamed_registrant(static calls + static field read/write + construction across two factories, node-validated).Note per #5960: the PR cargo-test gate runs unit tests only, so the failing acceptance suite rode in invisibly with #5938 — verified locally at the #5938 squash commit and at the pre-rebase tree (fails both), and green with this fix.
Code-only; metadata folded at merge.
Summary by CodeRabbit
Bug Fixes
Tests
Chores