# Sema: fix int arithmetic overflow checks · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/7702af5eb2d986d46b6978dafcf4b174313167e4)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 7702af5eb2d986d46b6978dafcf4b174313167e4

Requested commit: 7702af5eb2d986d46b6978dafcf4b174313167e4

Commit: 7702af5eb2d986d46b6978dafcf4b174313167e4

Tree: e18aec9e4935644c6dbb200820c803c286076ba5

Author: mlugg

Committer: Andrew Kelley

## Message

```
Sema: fix int arithmetic overflow checks

Previously, these checks worked by performing the arithmetic operation,
then checking whether the result fit in the type in question. Since all
values are now typed, this approach was no longer valid, and was
tripping some assertions due to trying to store too-large values in
smaller types.

Now, `intAdd`, `intSub`, `intMul` and `intDiv` all check for overflow,
and if it happens, re-do the operation with the result being a
`comptime_int`, and reporting the error (and vector index) to the caller
so that the error can be reported.

After this change, all test cases are passing.

```

## Parents

- [2a6b91874ae970c0fba63f8c1357da5a57feec27](https://git.cafe/gitcafe/zig/commit/2a6b91874ae970c0fba63f8c1357da5a57feec27?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/7702af5eb2d986d46b6978dafcf4b174313167e4?format=markdown)
