LYR-SEM0186
a macro's signature is not syntax to syntax
A macro declares a parameter or a result whose type is not a std.syntax type, declares type parameters, or, as an attribute macro (first parameter a declaration), returns something other than Decl or Decl[].
Explanation
A macro runs at compile time on the tree a site hands over, and gives back a tree that stands at the site. So its parameters and its result are types of std.syntax (Expr, Block, Ident, Literal, Type, Stmt[], Decl …), and it has no type parameters: syntax carries no types. An attribute macro takes the declaration it sits on and gives back the declarations that replace it.
Change the types to std.syntax types; for a value, take an Expr or a Literal and read it.
Wrong
import std.syntax { Expr, Ident };
macro name(n: int): Expr {
return Expr.Name(Ident.of("x"));
}
fn main(): void {
}
Right
import std.syntax { Expr };
macro echo(e: Expr): Expr {
return e;
}
fn main(): void {
}