fix(compiler): use span-overlap check for signal mutation ranges (#2785)#3019
Merged
viniciusdacal merged 2 commits intomainfrom Apr 28, 2026
Merged
fix(compiler): use span-overlap check for signal mutation ranges (#2785)#3019viniciusdacal merged 2 commits intomainfrom
viniciusdacal merged 2 commits intomainfrom
Conversation
Replace the point-membership check in `is_in_mutation_range` with a half-open span-overlap check (`ident.start < range.end && ident.end > range.start`), and rename the predicate to `overlaps_mutation_range`. The previous check only tested whether the identifier's first character sat inside a recorded mutation range. That happened to work because `mutation_analyzer` always records a span starting at the identifier's start, but any future tightening (e.g., the operator-only span for `+=`, or a span recorded on an inner sub-expression) would silently misclassify the identifier as outside the range and double-handle it by appending `.value` on top of the mutation rewrite. Applied the new predicate at all three call sites: identifier reads, assignment-expression LHS, and update-expression targets. Added three regression tests that inject a mutation range whose start is greater than the identifier's start and assert `.value` is suppressed at each site. Closes #2785 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…2785] Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
Closes #2785.
is_in_mutation_rangeinsignal_transformer.rsused a point-membership check onident.span.start(pos >= start && pos < end). The contract relied onmutation_analyzeralways recording a span that begins exactly at the identifier's first character — robust today, but silently broken by any future tightening (e.g., the operator-only span for+=, or a span recorded on an inner sub-expression).Replaced the predicate with a half-open span-overlap check (
ident_start < range.end && ident_end > range.start), renamed it tooverlaps_mutation_range, and applied it at all three call sites:visit_identifier_reference(signal reads)visit_assignment_expression(LHS of=,+=, etc.)visit_update_expression(++,--)Today this is observationally equivalent to the old check — every recorded range happens to start at the identifier's start, so both predicates agree. The change makes the predicate robust to future analyzer changes.
Public API Changes
None — internal compiler logic only.
Test plan
signal_transformer::testsinject a custom mutation range whose start is greater than the identifier's start and assert.valueis suppressed at each call site.signal_transformertests still pass.cargo test --all,cargo clippy --all-targets -- -D warnings,cargo fmt --all -- --checkall green.🤖 Generated with Claude Code