✓
Passing This code compiles and runs correctly.
Code
// Test: Branch with payload requires binding or explicit discard
//
// When a branch has a payload (e.g., `result { value: i32 }`), the branch
// handler MUST either bind it or explicitly discard with `_`:
//
// | result r |> // LEGAL - binds payload to 'r'
// | result _ |> // LEGAL - explicitly discards payload
// | result |> // ILLEGAL - payload exists but no binding
//
// This test verifies the compiler catches the illegal case.
const std = @import("std");
~event compute { x: i32 }
| result i32
~proc compute {
return .{ .result = x * 2 };
}
// BUG: This should be a compile error!
// The `result` branch has payload `{ value: i32 }` but no binding.
// Correct syntax would be: `| result _ |>` or `| result r |>` (if `r` is used)
~compute(x: 42)
| result |> std.io:println(text: "done")
Error Verification
Actual Compiler Output
error[KORU030]: branch 'result' has payload but no binding
--> structural_check:25:0
❌ Compiler coordination error: Unknown event referenced
error: CompilerCoordinationFailed
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/310_COMPTIME/310_039_branch_payload_requires_binding/backend.zig:9354:17: 0x104a564af in emit (backend)
return error.CompilerCoordinationFailed;
^
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/310_COMPTIME/310_039_branch_payload_requires_binding/backend.zig:9438:28: 0x104a572b7 in main (backend)
const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
^Test Configuration
MUST_FAIL
Expected Error:
branch 'result' has payload but no binding