Docs menu

E022: A module constant needs a value Turf can know right away

What compiler error E022 means, and how to fix it.

A top-level immut (pub immut when other files may use it) is a constant of its module, and Turf bakes its literal value directly into every place that uses it at compile time – there’s no shared storage behind the scenes. That means the value has to be something Turf can figure out immediately, like a plain number (a negative one such as -1 too), string, or true/false, not something computed from another variable or a function call.

Example
pub immut base: int = 10;pub immut total: int = base * 2;

Even though base * 2 is obviously 20 to a person reading this, a module constant can only hold a literal value written directly, not an expression – even a simple one like this. The fix is just to write out the actual value:

Example
pub immut total: int = 20;

If the real value genuinely needs to be computed (not just a simple literal you can write by hand), it can’t be a module constant. Instead, compute it in a function, where any expression works:

Example
fn total(): int {    return BASE * 2;}

This is a small tradeoff for how module constants work, but it’s a fair one: every file that uses a constant gets a value with zero runtime cost, right there at compile time.

The same rule explains the other way to trip this error: leaving the value out altogether.

Example
pub immut MAX_RETRIES: int;      // nothing to share

A module constant is its value, so it has to be given one on the spot:

Example
pub immut MAX_RETRIES: int = 3;

Run turf --explain E022 in a terminal to read this again.

Last updated: Oct 15, 2026Edit this page on GitHub

Esc

Type to search.