Lyricdev
GitHub

LYR-SEM0070

a field written twice in one initializer or 'with'

error ยท spec 03-types

A struct, class or variant initializer, an attribute, or a with copy names the same field more than once.

Explanation

Each field of a new value gets one value. A second write of the same field would either replace or be dropped, and neither is what the line says.

Write each field once.

Wrong

struct Point {
    x: int,
    y: int,
}

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

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