Lyricdev
GitHub

LYR-CG0002

a compile-time-only function called at run time

error ยท spec 12-stdlib

The program would call, at run time, a function of std.syntax that reads, builds or writes a syntax tree. Reported at every such call the built program reaches, the standard library's own among them.

Explanation

A syntax tree exists while the program compiles: macros and comptime sites read and write it, and the built program has no parser and no tree. The functions of std.syntax therefore have no run-time implementation.

Make the call inside a comptime site or a macro, and let the program use its result.

Wrong

import std.syntax { parseExpr };

fn main(): void {
    let e = parseExpr("1 + 2");
    assert(e.toSource() == "1 + 2");
}
import std.syntax { parseExpr };

fn main(): void {
    let text = comptime parseExpr("1 + 2").toSource();
    assert(text == "1 + 2");
}