V7021. The postfix increment or decrement has no effect because the variable is overwritten.
The analyzer has detected an error related to using postfix increment or decrement when writing to the same variable.
The example:
let value = 0;
....
value = value++; // <=
....
The value variable remains zero after the assignment. This happens because the postfix increment and decrement return the variable value before it is modified. The expression evaluates in the following order:
- reading the
valuevariable; - incrementing the value of the
valuevariable by one; - assigning the value obtained in step 1 to the
valuevariable.
As a result, the effect of the postfix increment or decrement is lost when the result is reassigned to the same variable.
This may be a typo, and the result should have been stored in another variable. In that case, the fixed code might look like this:
let value = 0;
let savedValue = ....;
....
savedValue = value++;
....
Otherwise, developers might have accidentally written the assignment, even though it is not really needed here:
let value = 0;
....
value++;
....