E1085: constant index outside the array

View source

An index that is a literal can be checked while compiling.

An index that is a literal can be checked while compiling. A literal at or above the capacity, or a negative literal, can never select a slot, so it is rejected instead of trapping when the program runs (ADR-0042). An index that is computed at run time is checked when it executes. The message names the index and the capacity. The error points at the index.

Example

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

Fix

Use an index below the capacity. The slots of Array[Int, 4] are 0 to 3. Raise the capacity when the program needs more slots.

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

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