# mixed-read-write-expression

Disallow reading and mutating the same place in one combined expression

Reading and mutating the same storage across subexpressions forces the result to depend on their evaluation order.
Instead, you SHOULD perform the mutation in a separate statement before using the resulting value.

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

## Reported

```ds title="main.ds"
function advance(): int32 {
    let value: int32 = 0;
    return value++ + value;
}
```

## Accepted

```ds title="main.ds"
function advance(): int32 {
    let value: int32 = 0;
    const previous = value;
    value++;
    return previous + value;
}
```

## Prior art

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

[language/linter/src/rules/suspicious/mixed_read_write_expression.rs:7](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/suspicious/mixed_read_write_expression.rs#L7)
