Home / Docs / Diagnostics

U2020: A parameter convention (edit, take) not matched at the call site, or declared where none is allowed

Release v0.4.0

A call does not match a parameter convention (edit, take), or a declaration has a convention where none is allowed.

Why Una rejects it

A caller writes edit p exactly where the parameter is declared edit, and take a exactly where it is declared take (spec/17 §3). Each of these is U2020:

A method receiver follows the same rule, as in edit total.add(by: 1). The argument of edit is a place, a binding or a field path of one, and the argument of take is a binding.

Operations and handlers cannot declare conventions, and neither can predicates: they are U2020 at the declaration.

The repair at a glance

src/demo.unadiff
  module demo

  pub kind Tally
    count: Int

  pub add(edit t: Tally, by: Int) -> Unit
  =
    t.count = t.count + by

  pub run() -> Int
  =
    let edit t = Tally(count: 0)
-   add(t, by: 2)
+   add(edit t, by: 2)
    t.count

Failing example

una.tomltoml
[package]
name = "demo"
version = "0.1.0"
edition = "0.2"
src/demo.unauna
module demo

pub kind Tally
  count: Int

pub add(edit t: Tally, by: Int) -> Unit
=
  t.count = t.count + by

pub run() -> Int
=
  let edit t = Tally(count: 0)
  add(t, by: 2)
  t.count

Fixed example

una.tomltoml
[package]
name = "demo"
version = "0.1.0"
edition = "0.2"
src/demo.unauna
module demo

pub kind Tally
  count: Int

pub add(edit t: Tally, by: Int) -> Unit
=
  t.count = t.count + by

pub run() -> Int
=
  let edit t = Tally(count: 0)
  add(edit t, by: 2)
  t.count