E1138: constant arithmetic overflows its type

View source

Integer arithmetic traps when the result does not fit the type of the operands (ADR-0115).

Integer arithmetic traps when the result does not fit the type of the operands (ADR-0115). When both operands are literals, the compiler computes the result itself and reports the overflow at compile time, instead of building a program that is sure to trap. This holds for +, - and *, and for / when the minimum value is divided by -1. The message names the operator and the type, and suggests +% to wrap or +| to saturate.

Example

actus
verb main() {
    erg total: u8 = 200u8 + 100u8;
}
actus
verb main() {
    erg quotient: i8 = -128i8 / -1i8;
}

Fix

Use a wider type, a wrapping or saturating operator, or a value that fits.

actus
verb main() {
    erg total: u32 = 200u32 + 100u32;
    erg wrapped: u8 = 200u8 +% 100u8;
    erg saturated: u8 = 200u8 +| 100u8;
}

Run actus explain E1138 in your terminal to read this entry offline. Browse Modules & rules or all error codes.