--- a/src/stockcount.una+++ b/src/stockcount.una@@ -62,3 +62,3 @@
for movement in day.movements
- let line = apply(edit ledger, movement: movement)+ let line = apply(ledger, movement: movement)
if error use "rejected: {reason(error)}"
Diagnostic
[U2020]Error: parameter `ledger` of `apply` is declared `edit`, so its argument is written `edit ledger`╭─[ src/stockcount.una:63:22 ]
│63│let line = apply(ledger, movement: movement)
│───┬──│╰──── parameter `ledger` of `apply` is declared `edit`, so its argument is written `edit ledger`││Help: repair 1: write `edit ledger`; edit src/stockcount.una:63:22..63:28 to "edit ledger"
││Note: run `una explain U2020` for an explanation
────╯
1 of 1 diagnostics have an edit that `una fix` applies (`una fix --dry-run` lists them)
Why: the call must show which bindings it may change, so a reader never has to open apply to find out. The mark points at the argument that lacks the word.
Fix: write edit ledger. The repair carries the edit, and una fix . applies it.
[U2019]Error:`ledger` is not editable; declare it `let edit ledger`, or the parameter `edit ledger`╭─[ src/stockcount.una:63:27 ]
│63│let line = apply(edit ledger, movement: movement)
│───┬──│╰──── `ledger` is not editable; declare it `let edit ledger`, or the parameter `edit ledger`││Note: run `una explain U2019` for an explanation
────╯
Why: an edit argument is assigned when the call returns, and a plain let binding is never assigned.
Fix:let edit ledger = …. The diagnostic points at the argument, and the fix is at the declaration.
[U2017]Error:`ledger` was passed by `take`, so it cannot be used afterwards╭─[ src/stockcount.una:67:65 ]
│66│let report = close(take ledger, lines: lines)
│───┬──│╰──── passed by `take` here67│Report(summary: report.summary, lines: report.lines, closing: ledger.counts)
│───┬──│╰──── `ledger` was passed by `take`, so it cannot be used afterwards││Note: run `una explain U2017` for an explanation
────╯
Why:take gave the ledger to close, and the diagnostic shows both places: the first mark is where it was taken, and the second where it is used.
Fix: use what close returns. report.closing already holds the counts.
--- a/src/stockcount.una+++ b/src/stockcount.una@@ -62,4 +62,4 @@
for movement in day.movements
- let line = apply(edit ledger, movement: movement)- if error use "rejected: {reason(error)}"+ let outcome = attempt apply(edit ledger, movement: movement)+ let line = if outcome.is_ok() then "applied" else "rejected"
lines = lines.append(item: line)
Diagnostic
[U3013]Error:`apply` is called with `edit` or `take`, so the call must be the whole expression of a statement or `let`; bind its result with `let` first╭─[ src/stockcount.una:63:27 ]
│63│let outcome = attemptapply(edit ledger, movement: movement)
│───────────────────┬──────────────────│╰──────────────────── `apply` is called with `edit` or `take`, so the call must be the whole expression of a statement or `let`; bind its result with `let` first││Note: run `una explain U3013` for an explanation
────╯
Why: a call with an edit or take argument is the whole expression of its statement, so that the binding it changes is updated on that line and nowhere else. The mark covers the whole call, inside the attempt.
Fix: handle the failure with a clause under the call, as close_day does with if error use. To pass the failure on, use if error pass.
[U2012]Error:`old` is allowed only in `ensures` clauses╭─[ src/stockcount.una:40:20 ]
│40│ ledger.applied = old(ledger).applied + 1│─────┬─────│╰─────── `old` is allowed only in `ensures` clauses││Note: run `una explain U2012` for an explanation
────╯
Why:old names the value on entry for the promise in the header. In the body, the parameter is simply its current value, so the mark points at old(ledger).
Fix: write ledger.applied + 1. To keep the entry value for later in the body, bind it first: let before = ledger.applied.