✓
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 { result: u32 } // REQUIRED
| ?warning { msg: []const u8 } // OPTIONAL
~proc process {
if (value > 100) {
return .{ .warning = .{ .msg = "Value too large" } };
}
return .{ .success = .{ .result = 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")
Test Configuration
Expected Behavior:
BACKEND_COMPILE_ERROR