Repository navigation
Commit 832f338
committed
[CodeQuality] Preserve parentheses around right-side assign in LogicalToBooleanRector
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 ffa770e commit 832f338
3 files changed
Lines changed: 34 additions & 0 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 | |
|---|---|---|---|
| |||
| 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 | + | |
| 484 | + | |
481 | 485 | | |
482 | 486 | | |
483 | 487 | | |
| |||
0 commit comments