-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
**= 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()] **= 2transpiles 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.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels