menu

almost-swapped

Disallow assignments that overwrite a value before swapping it

left = right; right = left assigns the original right value to both places because the first assignment overwrites the original left value. Instead, you SHOULD assign the reversed tuple to both places in parallel.

Reported

1function exchange(pair: { left: int32; right: int32 }): void {2    pair.left = pair.right;3    pair.right = pair.left;4}

Accepted

1function exchange(pair: { left: int32; right: int32 }): void {2    (pair.left, pair.right) = (pair.right, pair.left);3}