E1031: unknown field of a struct

View source

A struct literal or a field access names a field that the struct does not declare.

A struct literal or a field access names a field that the struct does not declare. ADR-0041 requires the compiler to reject unknown fields. The message names the field and the struct, and the error points at the field.

Example

actus
struct Point {
    x: Int,
}

verb main() {
    erg p: Point = Point { x: 1, z: 2, };
}
actus
struct Point {
    x: Int,
}

verb main() {
    erg p: Point = Point { x: 1, };
    println(int: p.z);
}

Fix

Use a field that the struct declares, or add the field to the struct.

actus check --format json offers this as a fix: rename the field to the one declared field whose name is close (a safe fix); nothing is offered when two fields are equally close.

actus
struct Point {
    x: Int,
    z: Int,
}

verb main() {
    erg p: Point = Point { x: 1, z: 2, };
}
actus
struct Point {
    x: Int,
}

verb main() {
    erg p: Point = Point { x: 1, };
    println(int: p.x);
}

Run actus explain E1031 in your terminal to read this entry offline. Browse Ownership & types or all error codes.