E1084: array index is not an integer

View source

An index selects a slot by number, so it must have an integer type (ADR-0042).

An index selects a slot by number, so it must have an integer type (ADR-0042). Int, Usize and the fixed-width integers are accepted. A Bool, a struct or a string is rejected. The message names the type that was found. The error points at the index expression.

Example

actus
verb main() {
    erg values: Array[Int, 4] = Array[Int, 4]();
    erg flag: Bool = true;
    erg x = values[flag];
}

Fix

Index with an integer. A Bool cannot be cast to one, because as converts only between integer types, so choose the slot with an integer value.

actus
verb main() {
    erg values: Array[Int, 4] = Array[Int, 4]();
    erg slot: Int = 1;
    erg x = values[slot];
}

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