LYR-CT0005
a form that does not run at compile time yet
Code run at compile time reaches something the compile-time interpreter does not run: a coroutine (a generator, sequence { }, a task), a native function without a compile-time implementation, a float parsed from text, or a syntax form std.syntax has no form for.
Explanation
The interpreter that runs comptime sites and macros covers most of the language, not all of it. What it does not run is refused at the site, so that a site never computes something different from the built program.
Compute the value at run time, or write the compile-time part without the construct.
Wrong
fn total(): int {
let s = sequence {
yield 1;
yield 2;
};
var sum = 0;
for (x in s) {
sum += x;
}
return sum;
}
fn main(): void {
let n = comptime total();
assert(n == 3);
}
Right
fn total(): int {
let s = sequence {
yield 1;
yield 2;
};
var sum = 0;
for (x in s) {
sum += x;
}
return sum;
}
fn main(): void {
let n = total();
assert(n == 3);
}