-
-
Notifications
You must be signed in to change notification settings - Fork 138
Negative expression formats as functionally different code #2486
Copy link
Copy link
Open
Description
Prettier 3.8.1
PHP Plugin 0.25.0
Options:
--parser phpInput:
<?php
$Y = 1;
$X = -$Y - 1;Output:
<php
$Y = 1;
$X = -($Y - 1);Expected behavior:
Prettier should preserve semantics. These two expressions are not equivalent:
-$Y - 1-($Y - 1)For example:
<?php
$Y = 1;
$a = -$Y - 1; // -2
$b = -($Y - 1); // 0
var_dump($a, $b);This outputs:
int(-2)
int(0)
So the transformation performed by Prettier changes the behavior of the code.
Additional context:
- Reproduced with
prettier@3.8.1and@prettier/plugin-php@0.25.0 - PHP version setting:
8.4 - Reproduced via CLI with:
npx prettier example.php --parser php --plugin=@prettier/plugin-phpThis appears to be an incorrect rewrite involving unary minus and binary subtraction precedence.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels