[U2004]Error: argument 2 of `show` needs a label; only the first argument may go without one│Help: repair 1: label it `charge`; edit src/shipping.una:78:14..78:24 to "charge: lamp.quote"
Why: in many languages arguments are matched by their place, so this habit comes first. In Una only the first argument may go without a label. The message names the argument by its place, 2, and the marks point at it, lamp.quote: a call, not the name charge, so punning does not apply.
Fix: write charge: lamp.quote, the label the Help line names. The repair is an exact edit, which una fix . applies. See U2004.
Give back the number itself when the order does not ship free:
diff
--- a/src/shipping.una+++ b/src/shipping.una@@ -65 +65 @@-pub report_line(order: Order, charge: Int) -> Text = if charge == 0 then "order {order.number}: ships free" else "order {order.number}: {money(charge)}"+pub report_line(order: Order, charge: Int) -> Text = if charge == 0 then "order {order.number}: ships free" else charge
Diagnostic
[U2001]Error:`report_line` returns `Text`, found `Int`
Why: both branches of the if give the function's result, which is a Text, and charge is an Int. The mistake comes from thinking of the else as a fallback that may be anything; it is the other half of one value. The marks point at the branch with the wrong type, not at the callers of report_line, which still rely on its header.
Fix: a text in both branches, such as "order {order.number}: {money(charge)}". See U2001.
[U2011]Error: this statement has type `Int`, and only `Unit` values can be discarded; bind the value with `let`╭─[ src/shipping.una:78:3 ]
│78│ lamp.quote
│─────┬────│╰────── this statement has type `Int`, and only `Unit` values can be discarded; bind the value with `let`
Why:lamp.quote gives an Int, and a statement may only throw away a value of type Unit. The quote is worked out, then lost: nothing names it, and the next line works it out again. The message says what to do.
Fix: remove the line, or bind the quote, let charge = lamp.quote, and pass charge on. See U2011.
6.6.4 A promise the caller needs, left out (U5001)
[U5001]Error: precondition `chair.quote >= 0` of this call is refuted╭─[ src/shipping.una:83:23 ]
│55│requires charge >= 0│─────┬─────│╰─────── requires clause│83│show(chair, charge: weekend_price(chair.quote))
│─────────────┬────────────│╰────────────── precondition `chair.quote >= 0` of this call is refuted
Why: the verifier proves the call of weekend_price with the header of quote, not its body. Without its ensures, a quote could be any Int, a negative one too, so the precondition of weekend_price, chair.quote >= 0, cannot be proved. The body never gives back a negative number, which is why the clause looked unneeded. The first mark shows the clause that asks, and the second the call that cannot give it.
Fix: put the clause back. A caller can rely only on what a header promises. See U5001.
6.6.5 A public function that prints without uses (U3004)
Make show public, in the short form, without its uses line:
diff
--- a/src/shipping.una+++ b/src/shipping.una@@ -67,6 +67,3 @@
--- Prints one line of the report.
-show(order: Order, charge: Int) -> Unit- uses @console: Console[print]-=- @console.print(report_line(order, charge))+pub show(order: Order, charge: Int) -> Unit = @console.print(report_line(order, charge))
Diagnostic
[U3004]Error:`@console` is used here, but this code declares no `uses`, so it is pure╭─[ src/shipping.una:68:47 ]
│68│pubshow(order: Order, charge: Int) -> Unit = @console.print(report_line(order, charge))
│────┬───│╰───── `@console` is used here, but this code declares no `uses`, so it is pure
Why: nothing is inferred for a pub function. A public header without uses promises a pure function, since its callers may be in other modules, and this body prints. The mistake often comes from making a working private function public: it checked before, because its uses was inferred, or written.
Fix: keep the uses @console: Console[print] line in its header, or keep show private. See U3004.
6.6.6 The long form for a one-line function (U7001)
Write ships_free with = on its own line:
diff
--- a/src/shipping.una+++ b/src/shipping.una@@ -45 +45,3 @@-pub ships_free(order: Order) -> Bool = order.goods >= 10_000 and order.parcel.zone is Home+pub ships_free(order: Order) -> Bool+=+ order.goods >= 10_000 and order.parcel.zone is Home
Diagnostic
[U7001]Error: lines 45 to 47 are not in canonical form
Why: a function without clauses whose body is one line has one canonical form, the short one. The long form looks tidier to many readers, but Una keeps one layout per function, so that every program reads the same way. The message names the lines, and the Help line holds the canonical text.
Fix: run una fmt ., which rewrites it, or una fix ., which applies the Help line's edit. See U7001.