Xo is experimental. The source is now public on GitHub, or try Xo in your browser.
Menu · XO0408

Docs

XO0408: block const initializer is not a compile time value

error · reported by the checker

A const declared inside a function body may use only literals, other constants, struct and enum construction, and collection literals of those. A top level const may also call effect free functions: it is computed once, on first use (decision 0332). Move the constant to the top level, or use a let binding. See core 3.1.

Example

fn g() -> Int { 1 }

fn f() -> Int {
  const X = g()
  X
}

Fix

fn g() -> Int { 1 }

const X = g()

fn f() -> Int {
  X
}

Run xo explain XO0408 for this text in a terminal, or see section 10.6 of the specification.