Lyricdev
GitHub

LYR-SEM0194

a quote in a program that does not reach std.syntax

error · spec 11-metaprogramming

A quote { … } stands in a program that does not import std.syntax.

Explanation

A quote builds a tree of std.syntax; without the module the program has no type for it.

Import std.syntax (and use quotes inside macros, where the trees are built).

Wrong

fn two(): int {
    let _ = quote { 1 + 1 };
    return 2;
}

fn main(): void {
}
import std.syntax { Expr };

macro two(): Expr {
    return quote { 1 + 1 };
}

fn main(): void {
}