# XO0502: assignment to an immutable binding or to a captured variable

Only `var` bindings, `var` parameters, `var` receivers, and their fields and elements can be assigned or passed to a `var` parameter. `let`, constants, pattern bindings, and `for` bindings are immutable. Closures capture by value, so mutating a captured `var` inside a closure is also an error; share state through a `Mutex` or `Atomic` instead. See core 3.3 and 5.2.

## Example

```xo
fn f() -> Int {
  let x = 1
  x = 2
  x
}
```

## Fix

```xo
fn f() -> Int {
  var x = 1
  x = 2
  x
}
```

Run `xo explain XO0502` for this text in a terminal, or see
[section 10.6 of the specification](../../spec/core/#106-diagnostic-codes).

