LYR-SEM0189
a macro expanded in its own module
A site name!(…) or @name stands in the module that declares the macro.
Explanation
A macro expands in the modules that import it. Its own module is checked and compiled first, so that the macro can run; a site there would need the macro before it exists.
Move the macro into a module of its own and import it, or move the site.
Wrong
import std.syntax { Expr };
macro echo(e: Expr): Expr {
return e;
}
fn main(): void {
assert(echo!(3) == 3);
}
Right
//- src/main.lyr
import app.macros { echo };
fn main(): void {
assert(echo!(3) == 3);
}
//- src/macros.lyr
import std.syntax { Expr };
pub macro echo(e: Expr): Expr {
return e;
}