Home / Learn / 8 Choosing
Release v0.4.0Edition 0.2
8.9 Recap and reference
Page 10 of 10
8.9.1 For agents
una --json check . gives every diagnostic as JSON. For A when that misses a variant:
json
{"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
- An
ifwithoutelseruns its lines only when its condition holds; it gives no value. - An
ifwithelse, over several lines, is the last line of its block, the value of aletor the value of an assignment. whentakes literal arms (is 2,is "RUG-07",is true) and range arms (in 1..<10,in 10..49); end them withelseunless they cover every value.- The arms are tried in order; prefer ranges that do not overlap, and put
elselast. - A pattern holds no condition: put an
ifinside the arm. - Inside a branch, the verifier knows its condition; after an
ifwhose branch fails, it knows the opposite. Elsewhere, it knows neither. - Guard values that can be bad; use
requiresfor 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
Optionfield.
8.9.3 Reference
Next:9 Repeating: for