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.
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:
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:
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.
pub immut MAX_RETRIES: int; // nothing to shareA module constant is its value, so it has to be given one on the spot:
pub immut MAX_RETRIES: int = 3;Run turf --explain E022 in a terminal to read this again.