Lyricdev
GitHub

LYR-SEM0191

a macro site's arguments do not fit the macro

error ยท spec 11-metaprogramming

A macro site writes more or fewer arguments than the macro takes, an argument is not the kind of syntax its parameter takes, a trailing block meets no Block or Stmt[] parameter, or an attribute macro sits on a declaration of another kind than its first parameter, takes nothing, or is written with fields.

Explanation

A macro's parameters are kinds of syntax, and each argument at the site must be one: an Ident takes a name, a Literal a literal, Expr an expression. A last parameter of type Block or Stmt[] may stand as a trailing block. An attribute macro takes the declaration it sits on as its first parameter, which says what kind of declaration it may sit on, and its further arguments stand in parentheses.

Write as many arguments as the macro takes, each of the kind it takes.

Wrong

//- src/main.lyr
import app.macros { echo };

fn main(): void {
    assert(echo!(3, 4) == 3);
}
//- src/macros.lyr
import std.syntax { Expr };

pub macro echo(e: Expr): Expr {
    return e;
}
//- 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;
}