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:
A function call that is used as array index for assignment shorthands (+=, -=, ++, ...) is executed twice:
test[getIndex()]++
gets translated totest[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: