E4088

E4088#

The record field is immutable.

MoonBit requires programmers to explicitly annotate which fields in a record they wish to be mutable. By default, all fields in a record are immutable. To make a field mutable, you need to add the mut keyword before the field.

错误示例#

struct S {
  value : Int
}

fn main {
  let s = { value: 42 }
  s.value = 43 // Error: The record field value is immutable.
  println(s.value)
}

建议#

To fix this error, you need to declare the field as mutable by adding the mut keyword before the field name.

struct S {
  mut value : Int
}

fn main {
  let s = { value: 42 }
  s.value = 43
  println(s.value)
}