# 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.

- Category: suspicious
- Level: warning
- Fix: none
- Scope: module

## Reported

```ds title="main.ds"
function exchange(pair: { left: int32; right: int32 }): void {
    pair.left = pair.right;
    pair.right = pair.left;
}
```

## Accepted

```ds title="main.ds"
function exchange(pair: { left: int32; right: int32 }): void {
    (pair.left, pair.right) = (pair.right, pair.left);
}
```

## Prior art

- [Clippy · almost_swapped](https://rust-lang.github.io/rust-clippy/master/index.html#almost_swapped)

[language/linter/src/rules/suspicious/almost_swapped.rs:6](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/suspicious/almost_swapped.rs#L6)
