E1097: constant needs a compile-time value

View source

A const is replaced by its value while compiling, and it has no storage at run time (ADR-0052).

A const is replaced by its value while compiling, and it has no storage at run time (ADR-0052). Its initializer may use literals, other constants and the checked operators, but not a call, a read of a binding or anything else that needs the program to run. The same code is reported for a pack offset that names a constant that has no value at compile time. The message names the constant. The error points at the declaration.

Example

actus
verb size() -> Int {
    return 4;
}

const LIMIT: Int = size();

verb main() {
}

Fix

Write the value from literals and other constants.

actus
const LIMIT: Int = 2 * 2;

verb main() {
}

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