LYR-SEM0019
a write to something that cannot be written
An assignment, ++/--, an index write or a call of a mut fn targets something that is not a writable place: a let, a parameter, a field without var, a temporary, a module let, a value reached through a let or through an optional chain.
Explanation
Only a place can be written: a var local or global, a var field reached through writable places, an element of a writable array. A value type is frozen where it is held by a let, and a mut fn writes its receiver, so it needs a writable one too.
Declare the binding or the field with var, or write to a copy held in a var.
Wrong
fn main(): void {
let n = 1;
n = 2;
let _ = n;
}
Right
fn main(): void {
var n = 1;
n = 2;
let _ = n;
}