[CodeQuality] Preserve parentheses around right-side assign in LogicalToBooleanRector#8152
Merged
Merged
Conversation
TomasVotruba
force-pushed
the
fix-logical-to-boolean-assign-parens
branch
from
July 8, 2026 10:34
832f338 to
b24637a
Compare
…lToBooleanRector Fixes rectorphp/rector#9799 When an assignment sits on the right/nested side of a converted boolean operator, the printer reused the Assign node verbatim and dropped the parentheses the pretty-printer would add in context: true and ($x = 42) and false; // became: true && $x = 42 && false; -> $x = (42 && false) = false The right-side reprint was guarded by !haveParens, but source parens live in the parent node token range (not the Assign node), so the guard skipped the reprint and the parens were lost anyway. Reprint unconditionally; the pretty-printer only adds parens when semantically needed.
TomasVotruba
force-pushed
the
fix-logical-to-boolean-assign-parens
branch
from
July 8, 2026 10:37
b24637a to
6475904
Compare
Member
Author
|
Let's ship it 👍 |
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.
Fixes rectorphp/rector#9799
LogicalToBooleanRectordropped the parentheses around an assignment sitting on the right/nested side of a boolean operator, silently changing semantics.Before
was rewritten to:
which PHP parses as
true && ($x = (42 && false))— so$xbecomesfalseinstead of42.After
Cause
BetterStandardPrinter::wrapBinaryOpWithBrackets()reprinted the right operand only when!haveParens. But the source parens in($x = 42)live in the parent node's token range, not theAssignnode's — sohaveParensreportstrue, the reprint is skipped, and the newly pretty-printed&&node drops them anyway.Reprint the right
Assignunconditionally. The pretty-printer is context-aware and only adds parentheses when semantically needed:Left-operand handling keeps its
!haveParensguard: removing it double-wraps cases like($c = $x) ?? $dwhose parent node preserves its own token gaps.