Repository navigation
fix(lower): VariantFields shadow fix — codex blocker on #565 - #568
Merged
Merged
Conversation
…ed names Codex blocker on #565 (merged without the fix): the new `SurfacePattern::VariantFields` branch in `lower.rs` used `arm_scope.contains_key(...)` as its duplicate-binding detector. `arm_scope` was cloned from the enclosing scope, so ANY outer binding that the pattern's field name shadows would fire a spurious "binds X more than once" diagnostic. Match-arm shadowing for VariantFields therefore broke for valid programs, while `VariantWith { binding: x }` already shadowed correctly via plain HashMap overwrite semantics. Fix: track a per-arm `introduced: HashSet<String>` of names this pattern brings in; duplicate-check against that set, not `arm_scope`. Pattern-local duplicates (`Foo { a: x, b: x }`) still reject. Outer shadowing (`fn read(w, inner: Int); match w { Wrap { inner: inner } => ... }`) now works. Regression test: `prereq2_named_payload_pattern_shadows_outer_scope_binding` exercises the exact shadow case the bug rejected. Existing duplicate-binding test (`prereq2_named_payload_pattern_duplicate_binding_fails_closed`) continues to pass — the pattern-local detector is unchanged. Full m1_substrate_test suite: 95 passed, 0 failed.
Contributor
Author
|
claude-review (director) — ✅ ship it Root-caused correctly. The scope-inversion is the real bug: Cross-checked:
Per TESTING.md:
Note: CI should clear shortly. Merge when green. |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the codex-flagged blocker that landed in #565 (merged): the new
SurfacePattern::VariantFieldslowering branch used the full outer scope as its duplicate-binding detector, so a legitimate match-arm shadow of an outer name got rejected as "binds X more than once."VariantWithalready shadowed correctly —VariantFieldsshould match that shape.The bug
lower.rs:5074-5103in theVariantFieldsarm:arm_scope.contains_key(&field.binding)checks the FULL outer scope cloned at line 5057. Any outer binding collides.The fix
Per-arm
introduced: HashSet<String>tracks only names THIS pattern brings in. Duplicate-check againstintroduced, notarm_scope. Pattern-local duplicates still reject; outer shadowing works via plain HashMap overwrite semantics (same asVariantWith).Regression test
prereq2_named_payload_pattern_shadows_outer_scope_binding:```
fn read(w: Wrapped, inner: Int) -> Int =
match w { Wrap { inner: inner } => inner.inner, Empty => inner }
```
inneris a fn parameter; match armWrap { inner: inner }shadows it. Previously rejected as duplicate; now compiles cleanly.Test plan
🤖 Generated with Claude Code