Repository navigation
Commit cfea3ba
authored
[CodeQuality] Preserve parentheses around right-side assign in LogicalToBooleanRector (#8152)
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.1 parent 30f9d4f commit cfea3ba
2 files changed
Lines changed: 16 additions & 3 deletions
File tree
- rules-tests/CodeQuality/Rector/LogicalAnd/LogicalToBooleanRector/Fixture
- src/PhpParser/Printer
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
478 | 478 | | |
479 | 479 | | |
480 | 480 | | |
481 | | - | |
482 | | - | |
483 | | - | |
| 481 | + | |
484 | 482 | | |
485 | 483 | | |
486 | 484 | | |
| |||
0 commit comments