Lyricdev
GitHub

LYR-CT0006

a use of a declaration the build leaves out

error ยท spec 11-metaprogramming

Code that is built for this target uses a declaration whose @When condition is false for it, so the declaration is not built.

Explanation

@When(condition) keeps a declaration only in the builds whose target meets the condition. A use the program would run must therefore stand where the same condition holds, or the program would call what does not exist.

Put the use under comptime if with the same condition, or give the declaration a counterpart for the other targets.

Wrong

@When(target.pointerWidth == 16)
fn narrow(): int {
    return 16;
}

fn main(): void {
    assert(narrow() == 16);
}
@When(target.pointerWidth == 16)
fn narrow(): int {
    return 16;
}

fn main(): void {
    comptime if (target.pointerWidth == 16) {
        assert(narrow() == 16);
    }
}