Error codes

E0412: constant initializer with an effect

In a terminal: auk explain E0412 prints this page.

On this page

Module constants (let at the top level) and imprint values are computed without any effects, so their initializers must be pure. Reading files, the clock or randomness happens in a function that declares the effect.

Wrong#

auk
let START = time.now()
fn main() { print(START) }

Fixed#

auk
fn main() uses time {
  let start = time.now()
  print(start)
}

Common causes#

  • Loading configuration into a global: load it in main and pass it along.
  • imprint computed from a file: embed the data as a literal instead.

Stuck on a word? Try the glossary. Got a compiler error? Look up its code. Improve this page