Lyricdev
GitHub

LYR-SEM0156

a place argument or parameter that is no place

error ยท spec 03-types

& hands a call something it may not write (a let, a temporary, a call's result), or a place parameter &p has a default or is params/variadic.

Explanation

A place parameter &n writes into a place the caller holds, and &x at the call shows which. That place must be one the caller may write: a var, a field or element of one, another place parameter. A let or a temporary is no such place. For the same reason a place parameter takes no default and is not params: both are values the call makes, not places of the caller's.

Declare the binding var, or store the temporary in a var first; drop the default or the params from a place parameter.

Wrong

fn increment(&n: int): void {
    n += 1;
}

fn main(): void {
    let x = 1;
    increment(&x);
}
fn increment(&n: int): void {
    n += 1;
}

fn main(): void {
    var x = 1;
    increment(&x);
}