✓
Passing Passing: the compiler rejects this program as expected.
Code
// Glyph discipline, the CHANNEL-CONSUMER case — sibling of 400_199 and
// 690_357-360. A `=>` inside a `std/channel(<name>)` consumer arm can never
// construct: the arm's `|>` chain grafts into the minted void unit
// (channel.units' drained-unit convention — no return contract), so the
// enclosing tor's branch cannot be produced from in there. Without this
// wall it dies in emitted Zig (`type 'void' does not support struct
// initialization syntax` inside the generated `__channel_*` handler).
import std/io
import std/proto
import std/channel
import std/pump
std/proto(Reading) { id: u64 }
pub tor mk { i: u64 } -> Reading
mk -> { id: i }
std/channel:new(inbox, capacity: 8) { reading: Reading }
std/channel(inbox)
! reading v |> std/io:print.ln("consumed {{ v.id:d }}") => ran
! closed |> std/io:print.ln("closed")
mk(i: 42): r |> std/channel:send(inbox, r)
| ok |> std/channel:close(inbox)
| ok |> std/io:print.ln("sent+closed")
| full |> std/io:print.ln("full")
| closed |> std/io:print.ln("send closed")
std/pump:create(main)
| drained |> std/io:print.ln("pump drained")
std/pump(main)
! step |> inbox-step()
! live |> inbox-live()
! wait i |> inbox-wait(i)
std/pump:run(main)
Actual compiler output
error[KORU102]: std/channel(inbox): `=>` inside a `! reading` arm has nothing to construct — the arm body grafts into a void synthesized unit, so a branch of the enclosing tor cannot be produced from in there. Hand the verdict out through the enclosing surface and branch after it returns.
--> tests/regression/600_STDLIB/699_CHANNEL/699_035_construct_glyph_in_consumer_arm/input.k:21:0
error[KORU161]: std/channel(inbox): unknown channel — no std/channel:new(inbox) found
--> tests/regression/600_STDLIB/699_CHANNEL/699_035_construct_glyph_in_consumer_arm/input.k:20:0
error[KORU161]: std/channel:close: no channel named 'inbox' — `std/channel:new(inbox, capacity: N) { kind: Proto }` declares it
--> tests/regression/600_STDLIB/699_CHANNEL/699_035_construct_glyph_in_consumer_arm/input.k:25:0
error[KORU161]: std/channel:send: no channel named 'inbox' — `std/channel:new(inbox, capacity: N) { kind: Proto }` declares it
--> tests/regression/600_STDLIB/699_CHANNEL/699_035_construct_glyph_in_consumer_arm/input.k:24:0
error[KORU161]: std/pump(main): `! step`'s body must end in a call to a declared tor - the pump composes compile-time-known verbs
--> tests/regression/600_STDLIB/699_CHANNEL/699_035_construct_glyph_in_consumer_arm/input.k:33:0Compiler must reject:
Compilation must fail with a diagnostic.
Flows
flow ~std/proto click a branch to expand · @labels scroll to their anchor
std/proto (Reading, source: id: u64)
flow ~new click a branch to expand · @labels scroll to their anchor
new (expr: inbox, capacity: 8, source: reading: Reading)
flow ~std/channel click a branch to expand · @labels scroll to their anchor
std/channel (inbox)
flow ~mk click a branch to expand · @labels scroll to their anchor
mk (i: 42)
flow ~create click a branch to expand · @labels scroll to their anchor
create (expr: main)
flow ~std/pump click a branch to expand · @labels scroll to their anchor
std/pump (main)
flow ~run click a branch to expand · @labels scroll to their anchor
run (main)
Test Configuration
MUST_ERROR