Error codes

E0320: assignment to something immutable

In a terminal: auk explain E0320 prints this page.

On this page

let bindings and ordinary parameters can't change. Only var bindings (and var parameters) can be assigned, pushed to or passed with &, so mutation is always declared.

Wrong#

auk
fn main() {
  let n = 1
  n += 1
  print(n)
}

Fixed#

auk
fn main() {
  var n = 1
  n += 1
  print(n)
}

Common causes#

  • Declaring with let a value that is later updated: use var.
  • Calling a mutating method (push, pop, insert) on a let list.
  • Assigning to a parameter: copy it into a var first, or make it a var parameter.

Stuck on a word? Try the glossary. Got a compiler error? Look up its code. Improve this page