✓
Passing This code compiles and runs correctly.
Code
// ============================================================================
// TEST: Pattern Branches Parser Support
// ============================================================================
// Verifies that the parser correctly handles [...] pattern branch syntax.
// Pattern branches allow opaque expressions as branch names for DSL transforms.
//
// The [...] content is passed through as the branch name - transforms interpret it.
// ============================================================================
// Simple event to test pattern branches
~event test_patterns {}
| ok {}
~proc test_patterns {
return .{ .ok = .{} };
}
// Test that pattern branches parse correctly
// The branch names are [GET /users/:id] etc - opaque to the compiler
~test_patterns()
| [GET /users/:id] |> ok {}
| [POST /users] |> ok {}
| [nested [brackets] work] |> ok {}
| [* -> stopped] |> ok {} // State machine style
| ok |> _ // Normal branch still works
// Verify nested patterns work
~test_patterns()
| [/admin/*] |>
test_patterns()
| [GET /dashboard] |> ok {}
| ok |> _
| ok |> _
Error Verification
Expected Error Pattern
Pattern branches without a transform produce KORU021 errors.
This test verifies that pattern branch SYNTAX parses correctly.
The validation correctly rejects unknown branches like [GET /users/:id]
when the event only declares 'ok'.
Expected errors:
- KORU021: unknown branch '[GET /users/:id]'
- KORU021: unknown branch '[POST /users]'
- etc.Actual Compiler Output
[PHASE 2.4] Calling run_pass for transforms\n[PHASE 2.5] Executing comptime_main() - running comptime flows
[PHASE 2.5] Comptime flows complete (31 items)
[PHASE 2.6] Rescanning transformed AST (31 items)
[PHASE 2.6] Rescan complete: 25 comptime events found
[0] std.compiler:requires
[1] std.compiler:flag.declare
[2] std.compiler:command.declare
[3] std.compiler:coordinate
[4] std.compiler:context_create
[5] std.testing:test
[6] std.testing:validate_mocks
[7] std.testing:test.with_harness
[8] std.testing:test.harness
[9] std.testing:assert
[10] std.testing:test.property.equivalent
[11] std.deps:deps
[12] std.deps:requires.system
[13] std.deps:requires.zig
[14] std.control:if
[15] std.control:for
[16] std.control:capture
[17] std.control:const
[18] std.build:requires
[19] std.build:variants
[20] std.build:config
[21] std.build:command.sh
[22] std.build:command.zig
[23] std.build:step
[24] std.template:define
error[KORU021]: continuation references unknown branch '[GET /users/:id]'
--> structural_check:21:0
error[KORU021]: continuation references unknown branch '[POST /users]'
--> structural_check:21:0
error[KORU021]: continuation references unknown branch '[nested [brackets] work]'
--> structural_check:21:0
error[KORU021]: continuation references unknown branch '[* -> stopped]'
--> structural_check:21:0
❌ Compiler coordination error: Incomplete branch coverage
error: CompilerCoordinationFailed
/Users/larsde/src/koru/tests/regression/200_COMPILER_FEATURES/210_PARSER/210_052_pattern_branches/backend.zig:9517:17: 0x104186433 in emit (backend)
return error.CompilerCoordinationFailed;
^
/Users/larsde/src/koru/tests/regression/200_COMPILER_FEATURES/210_PARSER/210_052_pattern_branches/backend.zig:9601:28: 0x1041871bf in main (backend)
const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
^Test Configuration
MUST_FAIL