✓
Passing Passing: the compiler rejects this program as expected.
Code
// PINS: `clear` refuses a store whose observer would silently stop being told.
//
// A `! removed` arm is a per-row observer. `clear` does not fire it — firing
// it once per row is exactly the cost `clear` exists to remove — so a store
// carrying one must also declare `! cleared` to say what emptying means for
// its observers. Refusing is the only honest option: emptying the store while
// quietly skipping the arm would leave the observer's own bookkeeping wrong
// with nothing on screen to say so.
//
// The diagnostic names THIS cause specifically. The sibling refusal — an
// owned column, whose obligations discharge one at a time — has its own
// message, because a store hitting one of these should not be sent to read
// about the other.
import std/io
import std/store
std/store:new(t) { n: 0[i64] }
std/store:new(rows, capacity: 4) { v: i64 }
! removed _ |> std/store:stored { t.n: t.n - 1 }
std/store:insert(rows) { v: 1 }
| row _ |> _
| full |> _
std/store:clear(rows)
std/io:print.ln("n {{ t.n:d }}")
Actual compiler output
error[KORU161]: std/store:clear(rows): this store carries a `! removed` arm and no `! cleared` arm. `clear` does NOT fire `! removed` - firing it once per row is exactly the cost `clear` exists to remove - so declare `! cleared <count>` to say what emptying means for this store's observers, or remove rows with `std/store:take`
--> tests/regression/600_STDLIB/690_STORE/690_266_clear_refuses_without_an_aggregate_arm/input.k:26:0Compiler must reject:
Compilation must fail with a diagnostic.
Flows
flow ~new click a branch to expand · @labels scroll to their anchor
new (t, source: n: 0[i64])
flow ~new click a branch to expand · @labels scroll to their anchor
new (rows, capacity: 4, source: v: i64)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (rows, source: v: 1)
flow ~clear click a branch to expand · @labels scroll to their anchor
clear (rows)
flow ~print.ln click a branch to expand · @labels scroll to their anchor
print.ln (expr: "n {{ t.n:d }}")
Test Configuration
MUST_ERROR