# E4087

Mutating something immutable, such as a variable or struct field.

MoonBit requires programmers to explicitly declare mutable variables and struct fields.
Notice that in MoonBit, variable mutability only refers to the variable itself,
not the value it holds.
So when you declare an immutable `let` value of type `Array[T]`, `Ref[T]`, or a
`struct` with mutable fields, you can still mutate the inner structure, but
cannot replace the value of the whole variable.

Tuples are always immutable. If you want mutability, use a `struct` with mutable fields instead.

## Erroneous Example

Variable mutation:

```{literalinclude} /sources/error_codes/4087_error/top.mbt
:language: moonbit
```

Struct field mutation:

```{literalinclude} /sources/error_codes/4087_error/top_1.mbt
:language: moonbit
```

## Suggestion

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

```{literalinclude} /sources/error_codes/4087_fixed/top.mbt
:language: moonbit
```
