# no-overflow-check-after-overflow

Disallow overflow tests that perform the overflowing operation first

Comparing an unsigned arithmetic result with an operand observes overflow only after it has occurred.
Instead, you MUST use checked arithmetic or the overflow flag returned by an overflowing operation.

- Category: correctness
- Level: error
- Fix: suggestion
- Scope: module

## Reported

```ds title="main.ds"
function overflows(left: uint32, right: uint32): boolean {
    return left + right < left;
}
```

## Accepted

```ds title="main.ds"
function overflows(left: uint32, right: uint32): boolean {
    return left.checkedAdd(right) === undefined;
}
```

## Prior art

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

[language/linter/src/rules/correctness/no_overflow_check_after_overflow.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/correctness/no_overflow_check_after_overflow.rs#L8)
