E1083: array capacity is not a positive constant

View source

Array[T, N] holds exactly N elements in storage whose size is fixed when the program is compiled (ADR-0042).

Array[T, N] holds exactly N elements in storage whose size is fixed when the program is compiled (ADR-0042). N must be a positive integer literal, a positive constant of type Usize, or a const generic parameter. Zero is rejected because the array would have no slot, and a runtime binding is rejected because its value is not known at compile time. The message names the capacity that was written. The error points at the capacity in the type.

Example

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

Fix

Use a positive literal or a named constant for the capacity.

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

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

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