# ambiguous-precedence

Require grouping where operator precedence is easy to misread

Mixed arithmetic, shift, bitwise, comparison, and logical operators can make evaluation order difficult to see.
Instead, you SHOULD parenthesize each nested operation whose precedence is not conventional arithmetic.

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

## Reported

```ds title="main.ds"
function mask(offset: int64, width: int64): int64 {
    return 1 << offset + width;
}
```

## Accepted

```ds title="main.ds"
function mask(offset: int64, width: int64): int64 {
    return 1 << (offset + width);
}
```

## Prior art

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

[language/linter/src/rules/suspicious/ambiguous_precedence.rs:12](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/suspicious/ambiguous_precedence.rs#L12)
