E1027: initializer does not match the declared type

View source

A binding with a declared type must be initialized with a value of that type.

A binding with a declared type must be initialized with a value of that type. Actus converts nothing implicitly, so Bool does not become Int. The message names the binding and both types. The error points at the declaration. A const is checked the same way: its value must have the declared type, so const FLAG: Bool = 1; is rejected. The unsuffixed integer literal arms of an if or case value take the declared integer type, so erg a: u8 = if c { 1 } else { 2 }; is accepted; arms of different types are still rejected. An assignment to a binding with a declared type is checked the same way, and the literal arms of an assigned if or case value take the binding's type, so a = if c { 3 } else { 4 }; is accepted too.

Example

actus
verb main() {
    erg n: Int = true;
}
actus
const FLAG: Bool = 1;

verb main() {
}
actus
const SCALE: f32 = 1;

verb main() {
}

Fix

Initialize the binding with a value of its type, or declare the type that the value has.

actus
verb main() {
    erg n: Int = 1;
}
actus
const FLAG: Bool = true;
const SCALE: f32 = 1.5;

verb main() {
}

Run actus explain E1027 in your terminal to read this entry offline. Browse Ownership & types or all error codes.