Lyricdev
GitHub

LYR-SEM0022

an expression statement without an effect

error · spec 07-statements

A statement consists of an expression whose value is discarded and which does nothing else: a literal, a name, an arithmetic expression, a with. Only calls, assignments, ++/--, throw and loops stand alone.

Explanation

An expression computed only to be thrown away is almost always a mistake — a missing assignment, a call without its parentheses, or a value meant to be returned.

Assign the value, return it, or bind it to _ when it is wanted for its effect only.

Wrong

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