Lyricdev
GitHub

LYR-SEM0009

array elements of different types

error ยท spec 08-expressions

An array literal without an expected type has elements whose types differ from the first element's.

Explanation

An array holds one element type. Without a declared type, the literal takes the first element's type and every other element must have exactly that type; nothing widens to a common one.

Make the elements agree, or declare the binding's type so each element is checked against it.

Wrong

fn main(): void {
    let _ = [1, "two", 3];
}
fn main(): void {
    let _ = [1, 2, 3];
}