Lyricdev
GitHub

LYR-CT0001

a panic while evaluating at compile time

error · spec 11-metaprogramming

Code run at compile time — a comptime site, an attribute's value, a macro — panics. The message names the panic and the run-time code (LYR-RT…) the built program would have ended with; the notes show where the evaluation went.

Explanation

A comptime site computes as the built program would: overflow, a division by zero, an index out of bounds, panic, assert, try! on an error and the rest panic there too. A panic at compile time has no program to end, so it is an error at the site, and the run-time code it carries is the one the catalog explains under LYR-RT…. A text std.syntax cannot parse is reported under this code as well.

Fix the computation or its arguments; the notes point to the frame that panicked.

Wrong

fn ratio(a: int, b: int): int {
    return a / b;
}

fn main(): void {
    let r = comptime ratio(1, 0);
    assert(r == 0);
}
fn ratio(a: int, b: int): int {
    return a / b;
}

fn main(): void {
    let r = comptime ratio(4, 2);
    assert(r == 2);
}