007 when guards

✓ Passing This code compiles and runs correctly.

Code

// Test 355_007: Optional Branches - when Guards + |? Interaction
//
// Verifies:
// 1. Using when guards for partial matching on optional branches
// 2. Bare continuation (no when) acts as else-case for when-guarded branches
// 3. |? catch-all handles OTHER optional branches not handled at all
//
// Note: KORU050 requires when-guarded branches have an else case (bare handler).
// The |? catch-all does NOT substitute for the else case — it catches
// entirely unhandled optional branches, not unmatched when-guards.

~import "$std/io"

// Event with required + optional branches
~event process { value: u32 }
| success { result: u32 }                    // REQUIRED
| ?warning { msg: []const u8, level: u32 }   // OPTIONAL with payload
| ?debug { info: []const u8 }                // OPTIONAL (never handled)

~proc process {
    // Return warning with different levels based on value
    if (value > 100) {
        return .{ .warning = .{ .msg = "Very large", .level = 10 } };
    }

    if (value > 50) {
        return .{ .warning = .{ .msg = "Moderately large", .level = 4 } };
    }

    if (value > 20) {
        return .{ .warning = .{ .msg = "Slightly large", .level = 1 } };
    }

    return .{ .success = .{ .result = value * 2 } };
}

// value=10 → success
~process(value: 10)
| success _ |> std.io:print.ln("SUCCESS")
| warning w when w.level > 5 |> std.io:print.ln("CRITICAL")
| warning w when w.level > 2 |> std.io:print.ln("MODERATE")
| warning _ |> std.io:print.ln("WARNING LOW")
|? |> std.io:print.ln("OPTIONAL IGNORED")

// value=150 → warning level 10 → matches first when guard (level > 5)
~process(value: 150)
| success _ |> std.io:print.ln("SUCCESS")
| warning w when w.level > 5 |> std.io:print.ln("CRITICAL")
| warning w when w.level > 2 |> std.io:print.ln("MODERATE")
| warning _ |> std.io:print.ln("WARNING LOW")
|? |> std.io:print.ln("OPTIONAL IGNORED")

// value=60 → warning level 4 → matches second when guard (level > 2)
~process(value: 60)
| success _ |> std.io:print.ln("SUCCESS")
| warning w when w.level > 5 |> std.io:print.ln("CRITICAL")
| warning w when w.level > 2 |> std.io:print.ln("MODERATE")
| warning _ |> std.io:print.ln("WARNING LOW")
|? |> std.io:print.ln("OPTIONAL IGNORED")

// value=25 → warning level 1 → no guards match → falls to bare | warning _
~process(value: 25)
| success _ |> std.io:print.ln("SUCCESS")
| warning w when w.level > 5 |> std.io:print.ln("CRITICAL")
| warning w when w.level > 2 |> std.io:print.ln("MODERATE")
| warning _ |> std.io:print.ln("WARNING LOW")
|? |> std.io:print.ln("OPTIONAL IGNORED")
input.kz

Expected

SUCCESS
CRITICAL
MODERATE
WARNING LOW

Actual

SUCCESS
CRITICAL
MODERATE
WARNING LOW

Test Configuration

MUST_RUN