Skip to content

Fix reassignment bug in PatternMatchingInstanceof.#5880

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_933267732
Jun 17, 2026
Merged

Fix reassignment bug in PatternMatchingInstanceof.#5880
copybara-service[bot] merged 1 commit into
masterfrom
test_933267732

Conversation

@copybara-service

Copy link
Copy Markdown
Contributor

Fix reassignment bug in PatternMatchingInstanceof.

Avoid refactoring if the variable assigned from the cast is reassigned, preventing compilation errors since pattern variables are implicitly final.

Changes:

  • Implement isReassigned helper using TreeScanner to check for assignments, compound assignments, and unary increments/decrements.
  • Update matchInstanceOf to avoid refactoring when the cast variable is reassigned.
  • Add test cases to PatternMatchingInstanceofTest covering reassignment, increment, and compound assignment cases.
  • Simplify logic in matchInstanceOf to use a single pass loop.

Avoid refactoring if the variable assigned from the cast is reassigned, preventing compilation errors since pattern variables are implicitly `final`.

Changes:
- Implement `isReassigned` helper using `TreeScanner` to check for assignments, compound assignments, and unary increments/decrements.
- Update `matchInstanceOf` to avoid refactoring when the cast variable is reassigned.
- Add test cases to `PatternMatchingInstanceofTest` covering reassignment, increment, and compound assignment cases.
- Simplify logic in `matchInstanceOf` to use a single pass loop.
PiperOrigin-RevId: 933419776
@copybara-service copybara-service Bot merged commit b096ccd into master Jun 17, 2026
@copybara-service copybara-service Bot deleted the test_933267732 branch June 17, 2026 01:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant