E1035: field of a frozen struct changed or moved

View source

While an abs view of a struct is live, the owner is frozen.

While an abs view of a struct is live, the owner is frozen. ADR-0046 says a frozen owner cannot mutate or move its fields, because the view must keep seeing the same data. A view lives until the end of the block that holds it. The error points at the assignment or the move. Assigning or moving the whole binding is reported as E1011.

Example

actus
struct Point {
    x: Int,
}

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

Fix

Change the field when no view exists. Put the view in an inner block so it ends first.

actus
struct Point {
    x: Int,
}

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

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