Lyricdev
GitHub

LYR-SEM0033

a block that gives no value where one is wanted

error · spec 08-expressions

A block that stands where a value is wanted — an arm of a match expression beside arms that give values, a clause of a try expression, a block expression — ends without a tail expression and does not leave on every path.

Explanation

A block gives a value through its tail, the last expression written without ;. A block that ends in a statement gives nothing, and in a position that wants a value it is only allowed when every path leaves it (return, throw, break).

End the block with a tail expression, or make it leave on every path.

Wrong

fn main(): void {
    let n = 3;
    let v = match (n) {
        0 => { let _ = n; }
        _ => n * 2,
    };
    let _ = v;
}
fn main(): void {
    let n = 3;
    let v = match (n) {
        0 => { 0 }
        _ => n * 2,
    };
    let _ = v;
}