wurstscript / WurstScript

Programming language and toolkit to create Warcraft III Maps
https://wurstlang.org
Apache License 2.0
226 stars 28 forks source link

Function calls as array index are executed twice when assignment shorthands are used #998

Closed Jampi0n closed 2 years ago

Jampi0n commented 3 years ago

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