Lyricdev
GitHub

LYR-SEM0229

a place of another type than the place parameter

error · spec 03-types

A place argument &x is of another type than the place parameter &p: T it is passed to; nothing widens into a place.

Explanation

A place parameter is the caller's place itself: the callee writes a value of its type into it. A place of another type — an int8 for an int — could not hold what is written, so a place takes its parameter's type exactly.

Declare the place with the parameter's type, or pass a value instead of a place.

Wrong

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

fn main(): void {
    var small: int8 = 1;
    increment(&small);
    let _ = small;
}
fn increment(&n: int): void {
    n += 1;
}

fn main(): void {
    var small = 1;
    increment(&small);
    let _ = small;
}