Lyricdev
GitHub

LYR-SEM0155

a caller attribute sits on the wrong parameter

error ยท spec 11-metaprogramming

@callerExpr, @callerLine or @callerFile is used where it cannot work: @callerExpr names no other parameter of the function, the parameter has the wrong type (string for @callerExpr and @callerFile, int for @callerLine), or it has no default.

Explanation

These attributes fill a parameter that a call leaves out: @callerExpr(x) with the source text of the argument written for parameter x, @callerLine with the call's line, @callerFile with its path. So @callerExpr names another parameter of the same function, the marked parameter has the type of what it receives, and it has a default, which a call that writes the argument keeps.

Name an existing other parameter, give the parameter the right type, and give it a default.

Wrong

fn f(x: int, @callerExpr(y) text: string = ""): string {
    return text;
}

fn main(): void {
    let _ = f(1);
}
fn f(x: int, @callerExpr(x) text: string = ""): string {
    return text;
}

fn main(): void {
    let _ = f(1);
}