Skip to content
ZOLO / TE003 Type · error

const value is not a compile-time constant

`const` requires a constant-foldable expression. Use `let` for runtime values.

Why this fires

A const declaration's value is not a compile-time constant expression. Unlike let, const must be fully evaluable at compile time — it cannot read a variable, call a non-constant function, or otherwise depend on something only known at runtime.

fn now_seconds() -> int { return 0 }

const START = now_seconds()
//            ^^^^^^^^^^^^^^ error[TE003]: const value must be a compile-time constant;
//                            use `let` for runtime values

Fix it

1. Use let instead

If the value genuinely needs to be computed at runtime, const is the wrong binding form:

let start = now_seconds()      // ok — let allows runtime values

2. Make the value a real constant

If the value should be fixed at compile time, replace the runtime expression with a literal or a comptime-evaluable expression (arithmetic on literals, references to other consts, etc.):

const START = 0                 // ok — a literal
const DOUBLE_START = START * 2  // ok — comptime-foldable from another const

See also

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br