○
Planned This feature is planned but not yet implemented.
Optional branches feature not fully implemented - see 918_optional_branches/IMPLEMENTATION_ROADMAP.md
Code
// Test 918b: Optional Branches - Mix Explicit Handling + |? Catch-All
//
// This test demonstrates:
// 1. Event with required and multiple optional branches
// 2. Handler explicitly handles SOME optional branches
// 3. Handler uses |? to catch remaining optional branches
// 4. This is the most realistic real-world pattern
const std = @import("std");
// Event with required + multiple optional branches
~event process { value: u32 }
| success { result: u32 } // REQUIRED: must be handled
| ?warning { msg: []const u8 } // OPTIONAL: handler CHOOSES to handle this explicitly
| ?debug { info: []const u8 } // OPTIONAL: handler uses |? for this
| ?trace { details: []const u8 } // OPTIONAL: handler uses |? for this
~proc process {
if (value > 100) {
return .{ .warning = .{ .msg = "Value too large" } };
}
if (value % 2 == 1) {
return .{ .debug = .{ .info = "Value is odd" } };
}
if (value < 5) {
return .{ .trace = .{ .details = "Very small value" } };
}
const doubled = value * 2;
return .{ .success = .{ .result = doubled } };
}
// Handler that mixes explicit handling with |? catch-all
// - success: handled explicitly (required)
// - warning: handled explicitly (we care about warnings)
// - debug, trace: caught by |? (we don't care about these)
~process(value: 10)
| success { result } |> std.debug.print("Success: {}\n", .{result})
| warning { msg } |> std.debug.print("Warning: {s}\n", .{msg})
|? |> std.debug.print("Optional branch (ignored)\n", .{})
~process(value: 150)
| success { result } |> std.debug.print("Success: {}\n", .{result})
| warning { msg } |> std.debug.print("Warning: {s}\n", .{msg})
|? |> std.debug.print("Optional branch (ignored)\n", .{})
~process(value: 7)
| success { result } |> std.debug.print("Success: {}\n", .{result})
| warning { msg } |> std.debug.print("Warning: {s}\n", .{msg})
|? |> std.debug.print("Optional branch (ignored)\n", .{})
~process(value: 2)
| success { result } |> std.debug.print("Success: {}\n", .{result})
| warning { msg } |> std.debug.print("Warning: {s}\n", .{msg})
|? |> std.debug.print("Optional branch (ignored)\n", .{})
Expected Output
Success: 20
Warning: Value too large
Optional branch (ignored)
Optional branch (ignored)
Test Configuration
MUST_RUN