✓
Passing This code compiles and runs correctly.
Code
// Test: ~for loop body can access outer scope bindings
//
// VISION: When ~for is in a pipeline, the loop body should be able to
// reference bindings from outer continuations (like init.data, p.count).
//
// This is the pattern used in nbody-optimized:
// ~get-data()
// | result init |> for(0..p.n)
// | each |> process(data: init.items[0..]) // <-- outer scope binding!
//
// BEFORE (broken): Synthetic proc can't access 'init' - scope error
// AFTER (working): Inlined code has direct access to 'init'
~import std/io
~import std/control
const std = @import("std");
// Event that returns data we reference in the loop
~event get-params {}
| result { count: u32, items: [5]i32 }
~proc get-params|zig {
return .{ .result = .{ .count = 3, .items = .{ 10, 20, 30, 40, 50 } } };
}
// Event to process items (void - no branches, for use inside for loop)
~event process-item { value: i32 }
~proc process-item|zig {
std.debug.print("Processing: {d}\n", .{value});
}
// The critical pattern: ~for in pipeline with outer scope reference
~get-params()
| result p |> for(0..p.count)
! each i |> process-item(value: p.items[i])
| done |> std/io:print.ln("All items processed")
Actual
Processing: 10
Processing: 20
Processing: 30
All items processed
Expected output
Processing: 10
Processing: 20
Processing: 30
All items processed
Test Configuration
MUST_RUN