Lyricdev
GitHub

LYR-CT0003

compile-time code that reaches outside the program

error ยท spec 11-metaprogramming

Code run at compile time calls a native function that reaches the world: the console, files, the clock, the network, processes, the environment.

Explanation

Code run at compile time computes from the program text alone, so that a build gives the same result every time and on every machine. The one way to read a file while compiling is embed.

Move the call to run time, or compute the value without it.

Wrong

import std.io { println };

fn loud(): int {
    println("hello");
    return 1;
}

fn main(): void {
    let n = comptime loud();
    assert(n == 1);
}
import std.io { println };

fn loud(): int {
    println("hello");
    return 1;
}

fn main(): void {
    let n = loud();
    assert(n == 1);
}