✓
Passing This code compiles and runs correctly.
Code
// Test 355_004: Optional Branches - Shape Validation Still Applies
//
// Verifies:
// 1. Optional branches are still subject to shape checking
// 2. "Optional" means "can be omitted", NOT "can be misused"
// 3. Handling a nonexistent branch name = compile error
~import std/io
// Event with required + optional branch
~event process { value: u32 }
| success u32 // REQUIRED
| ?warning []const u8 // OPTIONAL
~proc process|zig {
if (value > 100) {
return .{ .warning = "Value too large" };
}
return .{ .success = value * 2 };
}
// Handler references a branch that doesn't exist on this event
// "nonexistent" is not a branch of process — should fail compilation
~process(value: 150)
| success _ |> std/io:print.ln("OK")
| nonexistent _ |> std/io:print.ln("BAD")
Backend must reject with:
CONTAINS error[KORU021]
CONTAINS has no branch 'nonexistent'Error Verification
Actual Compiler Output
error[KORU021]: event 'input:process' has no branch 'nonexistent' (available: success, warning)
--> tests/regression/300_ADVANCED_FEATURES/355_OPTIONAL_BRANCHES/355_004_shape_error/input.kz:25:0
❌ Compiler coordination error: Incomplete branch coverage
error: CompilerCoordinationFailed
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/355_OPTIONAL_BRANCHES/355_004_shape_error/backend.zig:94:13: 0x100d4f18f in emit (backend)
return error.CompilerCoordinationFailed;
^
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/355_OPTIONAL_BRANCHES/355_004_shape_error/backend.zig:190:28: 0x100d4fe7b in main (backend)
const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
^Test Configuration
MUST_FAIL