Drop the guard of apply_sale in the day-to-day program, and set the price on every call:
src/store/sale.unadiff
--- 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
Diagnostic
[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 wherenot 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.
13.6.2 A condition in an edition 0.2 package (U0101)
Leave the restock step of section 13.1 on edition 0.2:
[U0101]Error: unexpected keyword `where`, expected `,` or `]`╭─[ src/restock.una:9:34 ]
│9│uses@supplier: Supplier[order wherenot 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.
[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.
13.6.4 Dropping the condition from a locked header (U3023, U5001)
Delete the condition from the header of apply_sale, and keep its guard:
src/store/sale.unadiff
--- 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]
=
Diagnostic
[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 proven42│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.
--- 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]"]
Diagnostic
[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.
[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.
13.6.7 A condition inside the narrowing brackets (U0101)
--- 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]
Diagnostic
[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 wherenot 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.