---
title: "13.6 Common mistakes"
url: https://una-lang.org/en/learn/authority/common-mistakes/
release: v0.4.0
edition: "0.2, 0.3"
---

# 13.6 Common mistakes

Each mistake is a small change to a package of this chapter, followed by what `una check .` reports.

## 13.6.1 Setting a price without the guard (U5001)

:::mistake
Drop the guard of `apply_sale` in the day-to-day program, and set the price on every call:

```diff include="day-to-day..mistakes/1:src/store/sale.una" context="1" title="src/store/sale.una"
--- a/src/store/sale.una
+++ b/src/store/sale.una
@@ -26,4 +26,3 @@
   let sale = sale_price(item.cents, percent)
-  if not dry_run
-    @prices.set_price(item.sku, cents: sale)
+  @prices.set_price(item.sku, cents: sale)
   sale
```

```text include="mistakes/1/expected/rendered.txt#L1-L12,L18"
[U5001] Error: `@prices.set_price` may run where `not dry_run` is not proven
    ╭─[ src/store/sale.una:27:3 ]
    │
 24 │   uses @prices: PriceList[set_price where not dry_run]
    │                                           ─────┬─────
    │                                                ╰─────── condition
    │
 27 │   @prices.set_price(item.sku, cents: sale)
    │   ────────────────────┬───────────────────
    │                       ╰───────────────────── `@prices.set_price` may run where `not dry_run` is not proven
    │
    │ Help 1: repair 1: guard the operation with `if not dry_run`
    │ Note 2: counterexample: dry_run = true, item = Item#0, item.cents = 0, item.sku = Text#0, percent = 0
```

*Why:* the header allows `set_price` only where `not dry_run` holds, and nothing in the body makes it hold before the operation. The counterexample has `dry_run = true`; the other values it lists, such as `Item#0`, are placeholders that any item fills. The marks show the condition in the header and the operation that may break it.

*Fix:* the first repair, a guard: `if not dry_run` around the operation, as the program has it. See [U5001](https://una-lang.org/en/docs/errors/U5001/).
:::

## 13.6.2 A condition in an edition 0.2 package (U0101)

:::mistake
Leave the restock step of [section 13.1](https://una-lang.org/en/learn/authority/conditions-on-operations-edition-0-3/#s13-1) on edition `0.2`:

```diff include="steps/01-conditions..mistakes/2:una.toml" context="1" title="una.toml"
--- a/una.toml
+++ b/una.toml
@@ -3,3 +3,3 @@
 version = "0.1.0"
-edition = "0.3"
+edition = "0.2"
 
```

```text include="mistakes/2/expected/rendered.txt"
[U0101] Error: unexpected keyword `where`, expected `,` or `]`
   ╭─[ src/restock.una:9:34 ]
   │
 9 │   uses @supplier: Supplier[order where not dry_run]
   │                                  ──┬──
   │                                    ╰──── unexpected keyword `where`, expected `,` or `]`
   │
   │ Note: run `una explain U0101` for an explanation
───╯
```

*Why:* edition `0.2` has no conditions on operations, so in its grammar the brackets of `uses` hold only names of operations, separated by commas. The word `where` there is a syntax error, and the marks point at it. Nothing in the code is wrong; the edition is.

*Fix:* write `edition = "0.3"` in `una.toml`, if the package may follow a preview edition, or remove the condition and keep the rule in a guard. See [U0101](https://una-lang.org/en/docs/errors/U0101/).
:::

## 13.6.3 Calling into a boundary by name (U3020)

:::mistake
Call the tag printer as you would call any function, without `with`:

```diff include="day-to-day..mistakes/3:src/store/sale.una" context="1" title="src/store/sale.una"
--- a/src/store/sale.una
+++ b/src/store/sale.una
@@ -46,3 +46,3 @@
     else
-      print_tag(item.name, cents: sale) with @console = @console
+      print_tag(item.name, cents: sale)
   saved
```

```text include="mistakes/3/expected/rendered.txt"
[U3020] Error: `print_tag` is in the boundary `vendor.tags` and needs `@console: Console[print]`, which a call into it grants only with `with`
    ╭─[ src/store/sale.una:47:7 ]
    │
 47 │       print_tag(item.name, cents: sale)
    │       ────────────────┬────────────────
    │                       ╰────────────────── `print_tag` is in the boundary `vendor.tags` and needs `@console: Console[print]`, which a call into it grants only with `with`
    │
    ├─[ src/vendor/tags.una:6:3 ]
    │
  6 │   uses @console: Console[print]
    │   ──────────────┬──────────────
    │                 ╰──────────────── the boundary's requirement
    │
    │ Help: repair 1: grant `with @console = @console[print]`, narrowed to the operations the callee declares, which lie within the ceiling of `vendor.tags`; edit src/store/sale.una:47:40..47:40 to " with @console = @console[print]"
    │
    │ Note: run `una explain U3020` for an explanation
────╯
1 of 1 diagnostics have an edit that `una fix` applies (`una fix --dry-run` lists them)
```

*Why:* `run_sale` holds `@console`, and outside a boundary the call would take it by name. A call into a boundary takes nothing by name, so that every grant to the module is written at the call. The first mark is the call, and the second the requirement inside the boundary that it leaves unmet.

*Fix:* grant it with `with`, as the line of `print_tag` in the day-to-day program does: `with @console = @console`. `una fix .` applies the repair instead, `with @console = @console[print]`, which grants the same, since `run_sale` holds only `print`. See [U3020](https://una-lang.org/en/docs/errors/U3020/).
:::

## 13.6.4 Dropping the condition from a locked header (U3023, U5001)

:::mistake
Delete the condition from the header of `apply_sale`, and keep its guard:

```diff include="day-to-day..mistakes/4:src/store/sale.una" context="1" title="src/store/sale.una"
--- a/src/store/sale.una
+++ b/src/store/sale.una
@@ -23,3 +23,3 @@
 pub apply_sale(item: Item, percent: Percent, dry_run: Bool) -> Int
-  uses @prices: PriceList[set_price where not dry_run]
+  uses @prices: PriceList[set_price]
 =
```

```text include="mistakes/4/expected/rendered.txt#L1,L14,L18,L22,L29,L33,L39"
[U3023] Error: the header of `apply_sale` lets `@prices.set_price` run where `not dry_run` does not hold, which `una.toml` locks
    │ Help: repair 1: restore the locked condition: write `set_price where not dry_run` in the header of `apply_sale`, or a condition that implies it; edit src/store/sale.una:24:36..24:36 to " where not dry_run"
    │ Note 2: counterexample: dry_run = true, percent = 4
[U5001] Error: `@prices.set_price` may run where `not dry_run` is not proven
 42 │     let sale = apply_sale(item, percent, dry_run)
    │ Help 1: repair 1: write the condition in the `uses` of `apply_sale`, as `set_price where ...`: `not dry_run` with each parameter of this function replaced by the parameter of `apply_sale` it is passed as; `apply_sale` then proves it where it runs `set_price`
    │ Note 2: counterexample: dry_run = true, items = List#0, items.len = 1, percent = 0, saved = 0
```

*Why:* two rules see the change. The header no longer keeps its lock in `una.toml`, which is U3023 at the header. And `run_sale`, whose condition still says `not dry_run`, calls a function whose header may now set a price on every call, which is U5001 at the call: the verifier reads the callee's header, not its guard.

*Fix:* write the condition back, as the U3023 repair says; `una fix .` makes that edit, and both diagnostics go away. See [U3023](https://una-lang.org/en/docs/errors/U3023/).
:::

## 13.6.5 A lock key without its module (U7002)

:::mistake
Name the locked function by its short name:

```diff include="day-to-day..mistakes/5:una.toml" context="1" title="una.toml"
--- a/una.toml
+++ b/una.toml
@@ -11,3 +11,3 @@
 [contracts]
-"store.sale.apply_sale" = ["@prices: PriceList[set_price where not dry_run]"]
+"apply_sale" = ["@prices: PriceList[set_price where not dry_run]"]
 "store.sale.run_sale" = ["@prices: PriceList[set_price where not dry_run]", "@console: Console[print]"]
```

```text include="mistakes/5/expected/rendered.txt"
[U7002] Error: [contracts] locks `apply_sale`, which is not a public function of this package
    ╭─[ una.toml:12:1 ]
    │
 12 │ "apply_sale" = ["@prices: PriceList[set_price where not dry_run]"]
    │ ──────┬─────
    │       ╰─────── [contracts] locks `apply_sale`, which is not a public function of this package
    │
    │ Note: run `una explain U7002` for an explanation
────╯
```

*Why:* a key of `[contracts]` is the qualified name of a public function: its module path, a dot, and its name. `apply_sale` alone names no function that una can find, so the lock guards nothing, and una refuses it rather than ignore it.

*Fix:* write `"store.sale.apply_sale"`. See [U7002](https://una-lang.org/en/docs/errors/U7002/).
:::

## 13.6.6 A 0.3 table in an edition 0.2 package (U7002)

:::mistake
Leave the boundary step of [section 13.2](https://una-lang.org/en/learn/authority/a-ceiling-for-a-module-boundaries/#s13-2) on edition `0.2`:

```diff include="steps/05-boundary..mistakes/6:una.toml" context="1" title="una.toml"
--- a/una.toml
+++ b/una.toml
@@ -3,3 +3,3 @@
 version = "0.1.0"
-edition = "0.3"
+edition = "0.2"
 
```

```text include="mistakes/6/expected/rendered.txt"
[U7002] Error: unknown table [boundaries] in una.toml
    ╭─[ una.toml:11:2 ]
    │
 11 │ [boundaries]
    │  ─────┬────
    │       ╰────── unknown table [boundaries] in una.toml
    │
    │ Note: run `una explain U7002` for an explanation
────╯
```

*Why:* `[boundaries]` and `[contracts]` exist only in edition `0.3`. In edition `0.2`, each is a table una does not know, and an unknown table is an error, not a setting that is silently ignored: a ceiling that una skipped would give no protection. The mark points at the table's name.

*Fix:* set `edition = "0.3"` if you want the preview's rules, or remove the table. See [U7002](https://una-lang.org/en/docs/errors/U7002/).
:::

## 13.6.7 A condition inside the narrowing brackets (U0101)

:::mistake
In the step of [Several operations, and calls outside a boundary](https://una-lang.org/en/learn/authority/a-ceiling-for-a-module-boundaries/#several-operations-and-calls-outside-a-boundary), restate the caller's condition when you narrow the binding for `mark_down`:

```diff include="steps/18-narrow-forms..mistakes/7:src/pricing.una" context="0" title="src/pricing.una"
--- a/src/pricing.una
+++ b/src/pricing.una
@@ -43 +43 @@
-  let sale = mark_down("DESK-02", dry_run) with @prices = @prices[price, set_price]
+  let sale = mark_down("DESK-02", dry_run) with @prices = @prices[price, set_price where not dry_run]
```

```text include="mistakes/7/expected/rendered.txt"
[U0101] Error: unexpected keyword `where`, expected `,` or `]`
    ╭─[ src/pricing.una:43:84 ]
    │
 43 │   let sale = mark_down("DESK-02", dry_run) with @prices = @prices[price, set_price where not dry_run]
    │                                                                                    ──┬──
    │                                                                                      ╰──── unexpected keyword `where`, expected `,` or `]`
    │
    │ Note: run `una explain U0101` for an explanation
────╯
```

*Why:* the brackets of a narrowed rebinding take names of operations only. `where` belongs in the brackets of `uses`, in a header, so here it is a syntax error, and the mark points at it. There is nothing to restate: the narrowed binding runs as the caller's, and keeps every condition that the caller's binding carries.

*Fix:* write the names alone, `@prices[price, set_price]`. See [U0101](https://una-lang.org/en/docs/errors/U0101/).
:::
