=+ or =- assigns a signed value where += or -= was meant

tx0/kotlin:reversed-compound-assignmentstrictwarningreliability/logicdepth fastbug

What it finds

total =+ price assigns +price to total, and count =- 1 assigns -1: the operator was meant to be += or -=, with its two characters swapped. The code compiles and quietly replaces the value instead of updating it.

Reported when = is followed by + or - with no space between them but a space after, the way a swapped compound operator is written. x = -1 and x=-1 are left alone.

From the rule's source, reversed_compound_assignment.rs.

Example from the rule's tests
fun total(prices: List<Int>): Int {    var sum = 0    var count = 10    for (price in prices) {        sum =+ pricetx0 reports: =+ assigns +price; += was probably meant        count =- 1tx0 reports: =- assigns -1    }    sum = -count    count = +sum    sum=-1    sum += 2    return sum + count}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/kotlin:reversed-compound-assignment" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/kotlin:reversed-compound-assignment] reason="..."

tx0 explain tx0/kotlin:reversed-compound-assignment shows the same in the terminal. Found a false positive? Report it.