E4087#
The variable is not mutable.
MoonBit requires programmers to explicitly declare mutable variables. Notice
that mutability in MoonBit only refers to the variable itself, not the value it
holds. This means for Array[T]
, Ref[T]
, and mutable fields in struct
, you
don't have to declare them as mutable.
Erroneous Example#
fn main {
let a = 0
a = 1 // Error: The variable a is not mutable.
println(a)
}
Suggestion#
To fix this error, you need to declare the variable as mutable by adding the
mut
keyword before the variable name.
fn main {
let mut a = 0
a = 1
println(a)
}