Lyricdev
GitHub

LYR-PAR0037

a field in an initializer without '='

error ยท spec 03-types

In a struct initializer, in the braces of an attribute, or after [f] in an initializer over infos, a field's name is not followed by =.

Explanation

An initializer gives each field its value with =: Point { x = 1, y = 2 }. A : there would read like a type, which is what : means everywhere else. A name alone, Point { x, y }, takes the binding of that name.

Write = between the field and its value.

Wrong

struct Point { x: int, y: int }

fn main(): void {
    let p = 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;
}