✓
Passing This code compiles and runs correctly.
Code
// Test 355_006: Optional Branches - API Evolution
//
// Verifies:
// 1. Event evolved by adding NEW optional branch
// 2. Old handler needs no change — the new optional branch absorbs
// 3. Adding optional branches never breaks existing handlers
// 4. Contrast: adding REQUIRED branches would break compilation (good!)
~import std/io
// VERSION 2: added ?debug branch (new in v2)
// success is REQUIRED, warning/debug are OPTIONAL
~tor process { value: u32 }
| success u32
| ?warning string
| ?debug string
~proc process|zig {
if (value < 5) {
return .{ .debug = "Small value" };
}
if (value > 100) {
return .{ .warning = "Large value" };
}
return .{ .success = value * 2 };
}
// Handler written for v1 — doesn't know about ?debug.
// Unnamed optional outcome → absorbs silently; no arm needed.
~process(value: 10)
| success _ |> std/io:print.ln("SUCCESS")
~process(value: 150)
| success _ |> std/io:print.ln("SUCCESS")
// value=2 → returns ?debug (new in v2) — unnamed → absorbs silently
~process(value: 2)
| success _ |> std/io:print.ln("SUCCESS")
Actual
SUCCESS
Expected output
SUCCESS
Flows
flow ~process click a branch to expand · @labels scroll to their anchor
process (value: 10)
flow ~process click a branch to expand · @labels scroll to their anchor
process (value: 150)
flow ~process click a branch to expand · @labels scroll to their anchor
process (value: 2)
Test Configuration
MUST_RUN