Lyricdev
GitHub

LYR-SEM0015

a field the type does not declare

error · spec 03-types

An initializer T { name = … }, a struct variant's initializer or a field pattern names a field that the struct, class or variant does not declare.

Explanation

An initializer and a destructuring pattern name the fields the declaration lists, and no others.

Correct the field's name, or declare the field on the type.

Wrong

struct Point { x: int, y: int }

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

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