✓
Passing Passing: the compiler rejects this program as expected.
Code
// Pins: a `captured` write under [parallel] whose fold operand reads the
// partitioned cell again is not a fold — `acc + i*acc` looks `+`-shaped at
// the top level, but the join's combine can only replay `cell op e_i` when
// `e_i` is cell-free. Serial answer is 9! = 362880; partitioned, the
// partials start at the identity and the join silently miscombines.
import std/io
capture { acc: 1[i64] }
! as a |> [parallel]for(1..9)
! each i |> captured { acc: a.acc + @as(i64, @intCast(i)) * a.acc }
| captured r |> std/io:print.ln("{{ r.acc:d }}")
Actual compiler output
error[KORU212]: [parallel]for: `a.acc + @as(i64, @intCast(i)) * a.acc` is not a provably additive write to `a.acc` — partition needs a combine law (provable monoid); write `acc: a.acc + <expr>` (or `*` / `@rem` fold) or drop [parallel]
--> tests/regression/400_RUNTIME_FEATURES/400_230_parallel_for_operand_reads_cell_refused/input.k:11:5Error output must contain
is not a provably additive writeFlows
flow ~capture click a branch to expand · @labels scroll to their anchor
capture (source: acc: 1[i64])
Test Configuration
MUST_ERROR