E1140: operands of different integer types

View source

An arithmetic, bitwise or comparison operator needs two operands of the same integer type.

An arithmetic, bitwise or comparison operator needs two operands of the same integer type. u8, u32 and Int are three different types, so a u8 cannot be added to a u32. Actus has no implicit numeric conversion, and the width of the arithmetic must be visible in the code. ADR-0119 sets this rule for arithmetic and bitwise operators, and ADR-0120 sets it for comparisons. An unsuffixed literal takes the type of the other operand, so small + 1 is accepted.

Example

actus
verb main() {
    erg small: u8 = 200u8;
    erg large: u32 = 100000u32;
    erg sum = small + large;
}

Fix

Convert one operand with as so both sides have the same type. The conversion is checked and traps if the value does not fit.

actus
verb main() {
    erg small: u8 = 200u8;
    erg large: u32 = 100000u32;
    erg sum = (small as u32) + large;
}

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