---
title: "8.9 Recap and reference"
url: https://una-lang.org/en/learn/choices/recap-and-reference/
release: v0.4.0
edition: "0.2"
---

# 8.9 Recap and reference

## 8.9.1 For agents

:::agents
`una --json check .` gives every diagnostic as JSON. For [A `when` that misses a variant](https://una-lang.org/en/learn/choices/common-mistakes/#a-when-that-misses-a-variant-u2007):

```json include="mistakes/1/expected/commands/json.txt#L2"
{"schema":"una.diagnostics/1","diagnostics":[{"schema":"una.diagnostic/1","code":"U2007","severity":"error","domain":"types","message":"`when` does not match variant `Returned` of `Status`","primary":{"file":"src/tracking.una","start":{"line":83,"col":3},"end":{"line":83,"col":7}},"related":[],"repairs":[{"rank":1,"escape_cost":0,"description":"add an arm for each missing variant, such as `is Returned`, or an `else` arm","edit":null}],"explain":"una explain U2007"}],"fixable":0}
```

U2007, U2008 and U5001 carry no `edit`, since only the author knows what a missing or misplaced arm should do. The block form of an `if` written with `then` (U0101) and the `==` form of U2009 carry exact edits, which `una fix .` applies. The compact rule: *an `if` without `else` is a statement; an `if` with `else` gives a value and is the last line or a `let`; `when` covers every variant, literal and range, or ends with `else`, which comes last; a pattern holds no condition; a fact holds on its path only; a recursive kind has a variant that ends.*
:::

## 8.9.2 Recap

:::recap
- An `if` without `else` runs its lines only when its condition holds; it gives no value.
- An `if` with `else`, over several lines, is the last line of its block, the value of a `let` or the value of an assignment.
- `when` takes literal arms (`is 2`, `is "RUG-07"`, `is true`) and range arms (`in 1..<10`, `in 10..49`); end them with `else` unless they cover every value.
- The arms are tried in order; prefer ranges that do not overlap, and put `else` last.
- A pattern holds no condition: put an `if` inside the arm.
- Inside a branch, the verifier knows its condition; after an `if` whose branch fails, it knows the opposite. Elsewhere, it knows neither.
- Guard values that can be bad; use `requires` for the caller's mistakes, a refined kind for rules that hold everywhere.
- A recursive kind needs a variant that does not contain it, or an `Option` field.
:::

## 8.9.3 Reference

:::reference
- Construct pages: [`when`](https://una-lang.org/en/docs/language/control-flow/when/), [`kind`](https://una-lang.org/en/docs/language/types/kind/), [`example`](https://una-lang.org/en/docs/language/examples/example/)
- Prelude: [`Option`](https://una-lang.org/en/docs/std/)
- Commands: [`una fix`](https://una-lang.org/en/docs/cli/fix/), [`una obligations`](https://una-lang.org/en/docs/cli/obligations/)
- Diagnostics: [U0101](https://una-lang.org/en/docs/errors/U0101/), [U1001](https://una-lang.org/en/docs/errors/U1001/), [U1002](https://una-lang.org/en/docs/errors/U1002/), [U2001](https://una-lang.org/en/docs/errors/U2001/), [U2002](https://una-lang.org/en/docs/errors/U2002/), [U2007](https://una-lang.org/en/docs/errors/U2007/), [U2008](https://una-lang.org/en/docs/errors/U2008/), [U2009](https://una-lang.org/en/docs/errors/U2009/), [U5001](https://una-lang.org/en/docs/errors/U5001/), [U5002](https://una-lang.org/en/docs/errors/U5002/), [U6003](https://una-lang.org/en/docs/errors/U6003/)
- Specification: [grammar](https://una-lang.org/en/docs/spec/02-grammar/), [types](https://una-lang.org/en/docs/spec/03-types/), [static semantics](https://una-lang.org/en/docs/spec/10-static-semantics/), [verification](https://una-lang.org/en/docs/spec/12-verification/), [memory model](https://una-lang.org/en/docs/spec/17-memory-model/)
:::
