Lyricdev
GitHub

LYR-SEM0187

a macro called as a function

error · spec 11-metaprogramming

A macro's name is called like a function, name(…), instead of being expanded with name!(…).

Explanation

A macro is never called as a function nor used as a value: it runs at compile time, and its site is written with ! so that a reader sees where code is generated.

Write the site as name!(…).

Wrong

//- 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;
}
//- 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;
}