E1051: mutation of a read-only binding

View source

An abs binding is a read-only view (ADR-0016).

An abs binding is a read-only view (ADR-0016). It lets code inspect a value that belongs to someone else, so assigning to it would change a value that the view does not own. This applies to an abs parameter, to a local abs binding and to a payload binding of a case, which is an abs binding too. The error points at the assignment. Assigning to the owner while a view of it is alive is a different error, E1011.

Example

actus
verb bump(abs n: Int) {
    n = 2;
}

verb main() {
}
actus
verb main() {
    erg count: Int = 1;
    abs view = ref count;
    view = 2;
}

Fix

Change the value through an owner. Declare the parameter erg or ins when the verb must change it, or assign to the owner instead of the view.

actus
verb bump(ins n: Int) {
    n = 2;
}

verb main() {
}
actus
verb main() {
    erg count: Int = 1;
    count = 2;
    abs view = ref count;
    println(int: view);
}

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