✓
Passing Passing: the compiler rejects this program as expected.
Code
// `recv` on a kind whose proto carries owned leaves must refuse: `| some v`
// binds the bare payload with no mint, and per-path debts only exist where
// the obligate step runs — the `!` arm. Composite custody consumes by arms
// (699_031); recv is the shape that can't see them.
import std/io
import std/proto
import std/channel
import std/pump
import app/lib/res
std/proto(Env) {
r1: *app/lib/res:Resource<owned!>
r2: *app/lib/res:Resource<owned!>
}
std/channel:new(inbox, capacity: 8) { env: Env }
std/channel:recv(inbox)
| some v |> std/io:print.ln("got")
| none |> std/io:print.ln("none")
| closed |> std/io:print.ln("closed")
Supporting Files
// A minimal OWNED-POINTER resource type (non-string), for generalizing B-narrow
// past std/string. `new` issues <owned!>; `free` is the canonical VOID
// discharger consuming <!owned>; `tag` borrows to read a field.
const std = @import("std");
const Resource = struct { tag: i64 };
~pub tor new { } -> *Resource<owned!>
~proc new|zig {
const r = std.heap.page_allocator.create(Resource) catch unreachable;
r.* = .{ .tag = 42 };
return r;
}
// Canonical discharger: consumes <!owned>, frees the resource. Void (no output).
~pub tor free { r: *Resource<!owned> }
~proc free|zig {
std.heap.page_allocator.destroy(r);
}
// Borrow: read the tag without consuming the obligation.
~pub tor tag { r: *Resource<owned> } -> i64
~proc tag|zig {
return r.tag;
}
Actual compiler output
error[KORU161]: std/channel:recv(inbox): kind 'env' carries owned leaves ('Env' fields carry obligations) — `| some v` can't mint per-path debts; consume by `!` arms: `std/channel(inbox) ! env v |> ...`
--> tests/regression/600_STDLIB/699_CHANNEL/699_033_recv_composite_kind_refused/input.k:18:0Must fail at runtime with:
CONTAINS owned leaves
CONTAINS armsError output must contain
owned leavesFlows
flow ~std/proto click a branch to expand · @labels scroll to their anchor
std/proto (Env, source: r1: *app/lib/res:Resource<owned!>
r2: *app/lib/res:Resource<owned!>)
flow ~new click a branch to expand · @labels scroll to their anchor
new (expr: inbox, capacity: 8, source: env: Env)
flow ~recv click a branch to expand · @labels scroll to their anchor
recv (expr: inbox)
Test Configuration
MUST_ERROR