Lyricdev
GitHub

LYR-SEM0226

a 'return' without the value the function returns

error · spec 07-statements

A bare return; stands in a function, a lambda or a coroutine whose result is not void.

Explanation

A function that returns a value returns one on every path: return; leaves without it. Only a void function, and a coroutine whose result is void, ends with a bare return;.

Write the value — return 0; — or change the result to void.

Wrong

fn twice(x: int): int {
    if (x < 0) {
        return;
    }
    return x * 2;
}

fn main(): void {
    let _ = twice(1);
}
fn twice(x: int): int {
    if (x < 0) {
        return 0;
    }
    return x * 2;
}

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