Function calls as array index are executed twice when assignment shorthands are used
Jampi0n opened this issue · comments
A function call that is used as array index for assignment shorthands (+=, -=, ++, ...) is executed twice:
test[getIndex()]++
gets translated to test[getIndex()] = test[getIndex()] + 1
The function can return different values in each call and could also have side effects that are repeated.
The expected behavior would be to have a temporary variable which stores the return value and use that variable as index:
tmp = getIndex()
test[tmp] = test[tmp] + 1