Lyricdev
GitHub

LYR-PAR0055

an initializer at the start of a statement

error · spec 03-types

A statement begins with Name { … } whose braces read as an initializer's: Point { x = 1 };, or a call with a trailing block whose assignment lost its ;, run { total = 5 }.

Explanation

An initializer builds a value, and a statement that is only an initializer would drop it; at the start of a statement the braces would also read like a block. A trailing block holds statements, so an assignment in it ends with ; — the note says so when that is the likelier meaning.

Bind the value with let, or end the block's statement with ;.

Wrong

struct Point { x: int, y: int }

fn main(): void {
    Point { x = 1, y = 2 };
}
struct Point { x: int, y: int }

fn main(): void {
    let p = Point { x = 1, y = 2 };
    let _ = p.x + p.y;
}