✓
Passing This code compiles and runs correctly.
Code
// ============================================================================
// VERIFIED REGRESSION TEST - DO NOT MODIFY WITHOUT DISCUSSION
// ============================================================================
// Test 208: Proc as Flow Expression
// Tests that ~proc name = flow syntax works as implicit return
// ============================================================================
const std = @import("std");
~event validate { val: i32 }
| positive { val: i32 }
| negative { val: i32 }
~proc validate {
if (val > 0) return .{ .positive = .{ .val = val } };
return .{ .negative = .{ .val = -val } };
}
~event compute { value: i32 }
| result { doubled: i32 }
// Pure flow proc - entire body is a flow expression
~proc compute = validate(val: value)
| positive p |> result { doubled: p.val * 2 }
| negative n |> result { doubled: 0 }
~event run_test { }
| done { }
~proc run_test {
// Test with positive value
const r1 = ~compute(value: 21)
| result r |> result { doubled: r.doubled }
std.debug.assert(r1.result.doubled == 42);
std.debug.print("✅ Positive: 21 * 2 = {}\n", .{r1.result.doubled});
// Test with negative value
const r2 = ~compute(value: -5)
| result r |> result { doubled: r.doubled }
std.debug.assert(r2.result.doubled == 0);
std.debug.print("✅ Negative: -5 → doubled = {}\n", .{r2.result.doubled});
return .{ .done = .{} };
}
~run_test()
| done |> _
Expected Output
✅ Positive: 21 * 2 = 42
✅ Negative: -5 → doubled = 0
Test Configuration
MUST_RUN