Error codes

E0311: & on an argument for a non-var parameter

In a terminal: auk explain E0311 prints this page.

On this page

&x marks an argument the callee may change, which only var parameters can do. This parameter isn't var, so the & is misleading and rejected.

Wrong#

auk
fn show(xs: [int]) { print(xs) }
fn main() {
  var a = [1]
  show(&a)
}

Fixed#

auk
fn show(xs: [int]) { print(xs) }
fn main() {
  var a = [1]
  show(a)
}

Common causes#

  • Using & to "pass by reference" for speed: Auk copies cheaply (copy-on-write).
  • The callee was meant to change it: declare the parameter xs: var [int].

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