**= and //= expand to target = func(target, val), which evaluates the target expression twice. Fine for simple variables, but wrong if the target has side effects.
def f():
print("called")
return 0
arr = [1, 2, 3]
arr[f()] **= 2
transpiles to:
arr[f()] = math.powi(arr[f()], 2)
f() gets called twice. Should use a temp variable for complex targets:
tmp := f()
arr[tmp] = math.powi(arr[tmp], 2)
Only affects **= and //= since those are the operators that expand to function calls. Regular +=, -= etc. use V's native operators and don't have this issue.
**=and//=expand totarget = func(target, val), which evaluates the target expression twice. Fine for simple variables, but wrong if the target has side effects.transpiles to:
f()gets called twice. Should use a temp variable for complex targets:Only affects
**=and//=since those are the operators that expand to function calls. Regular+=,-=etc. use V's native operators and don't have this issue.