misrefactored_assign_op
Finds a += a + b, an update that applies the operator to a twice.
Category correctness, deny by default.
#import "Basic";
main :: () {
total := 10;
price := 5;
total += total + price;
print("%\n", total);
}error[misrefactored_assign_op]: `total += total + ...` applies `+` to `total` twice
--> example.jai:7:5
|
7 | total += total + price;
| ^^^^^^^^^^^^^^^^^^^^^^
|
help: `+=` already starts from `total`: write `total += price`
|
7 ~ total += price;
|
= note: `misrefactored_assign_op` is `deny` by default#import "Basic";
main :: () {
total := 10;
price := 5;
total += price;
print("%\n", total);
}The same operator on both sides, a side-effect-free target of a number type spelled the same in both places (a op= a op b), and for + * & | ^ on integers also a op= b op a.