Bug Report
Hello,
My apologies for the double bug report, as this one seems closely related to #9807 : I thought assignments were parenthesized correctly (after being rewritten by LogicalToBooleanRector) when they were part of a binary operation, but that's only the case for simple assignments (=). Composed assignments still get rewritten without the required parentheses (and existing parentheses get removed).
Minimal PHP Code Causing Issue
See: https://getrector.com/demo/13531d14-0f84-413a-a23d-3d1337f0e8ab
<?php
$x = 0;
2 * $x += 42 and true; # → true, and $x is 42
$x = 0;
2 * ($x += 42) and true; # → true, and $x is 42
(The issue is the same with all composed assignments.)
This example gets rewritten as:
<?php
$x = 0;
2 * $x += 42 && true; # → 2 instead of true, and $x is 1 instead of 42
$x = 0;
2 * $x += 42 && true; # → 2 instead of true, and $x is 1 instead of 42
Responsible rule: LogicalToBooleanRector
Expected Behaviour
Rector should have added parentheses (or kept the existing ones) around the composed assignment:
<?php
$x = 0;
2 * ($x += 42) && true; # → true, and $x is 42 (OK)
$x = 0;
2 * ($x += 42) && true; # → true, and $x is 42 (OK)
Maybe the test on line 487 of BetterStandardPrinter.php should also handle in a similar fashion the case where the right-hand side of the binary operator is a composed assignment (AssignOp)?
Again, thank you very much! :)
Cheers,
Glop
Bug Report
Hello,
My apologies for the double bug report, as this one seems closely related to #9807 : I thought assignments were parenthesized correctly (after being rewritten by
LogicalToBooleanRector) when they were part of a binary operation, but that's only the case for simple assignments (=). Composed assignments still get rewritten without the required parentheses (and existing parentheses get removed).Minimal PHP Code Causing Issue
See: https://getrector.com/demo/13531d14-0f84-413a-a23d-3d1337f0e8ab
(The issue is the same with all composed assignments.)
This example gets rewritten as:
Responsible rule:
LogicalToBooleanRectorExpected Behaviour
Rector should have added parentheses (or kept the existing ones) around the composed assignment:
Maybe the test on line 487 of
BetterStandardPrinter.phpshould also handle in a similar fashion the case where the right-hand side of the binary operator is a composed assignment (AssignOp)?Again, thank you very much! :)
Cheers,
Glop