✓
Passing Passing: the compiler rejects this program as expected.
Code
// An `! each` over a member-expression iterable (`for(bag.items)` — not a
// range, not an `&[_]T{…}` literal, not a bare `for(name)`) has no element
// type the sweep boundary can name. The refusal names the iterable and the
// teaching: lift the value through a typed binding first.
import std/io
import std/store
std/store:new(spec, capacity: 8) { d: i64 }
std/store:insert(spec) { d: 10 }
pub tor run { bag: { items: [_]i64 } }
run = std/store:query(spec)
! query s
|> for(bag.items)
! each i |> std/store:query(spec)
! query p when p.d == i
|> std/io:print.ln("hit")
Actual compiler output
error[KORU161]: std/store:query(spec): the sweep body reads 'i', bound by `! each` over `bag.items` — the iterable's element type is not derivable at the sweep boundary. A range `a..b`, an `&[_]T{…}` literal, or a `[]T`/`[N]T` iterable names one; anything else needs the value lifted through a typed binding first.
--> tests/regression/600_STDLIB/690_STORE/690_384_each_member_iterable_refuses/input.k:15:13Must fail at runtime with:
ERROR_AT 15Error output must contain
element type is not derivableFlows
flow ~new click a branch to expand · @labels scroll to their anchor
new (spec, capacity: 8, source: d: i64)
flow ~insert click a branch to expand · @labels scroll to their anchor
insert (spec, source: d: 10)
subflow ~run click a branch to expand · @labels scroll to their anchor
query (spec)
Test Configuration
MUST_ERROR LANGUAGES: zig