Home / Docs / Diagnostics

U2019: Assignment to a binding that is not editable

Release v0.4.0

The code assigns to a binding that is not editable.

Why Una rejects it

Only a binding declared let edit, or a parameter declared edit, can be assigned, have a field assigned, or be passed as edit (spec/17 §2). A plain let and a plain or take parameter are fixed.

A lambda captures the value a binding has when the lambda is created. So inside a lambda a captured binding is not editable either (spec/17 §5 rule 4).

How to fix it

The repair at a glance

src/demo.unadiff
  module demo

  pub total(xs: List[Int]) -> Int
  =
-   let sum = 0
+   let edit sum = 0
    sum = xs.sum
    sum

Failing example

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

pub total(xs: List[Int]) -> Int
=
  let sum = 0
  sum = xs.sum
  sum

Fixed example

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

pub total(xs: List[Int]) -> Int
=
  let edit sum = 0
  sum = xs.sum
  sum