E4087#
变量是不可变的。
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.
错误示例:#
fn main {
let a = 0
a = 1 // Error: The variable a is not mutable.
println(a)
}
建议#
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)
}