✓
Passing Passing: the compiler rejects this program as expected.
Code
// NEGATIVE TEST — orisha:router must reject TERMINAL (`|`) pattern branches.
//
// The router dispatches INTO the matched route — effect semantics — so its
// pattern branches must be effect branches (`!`). The `[GET /path]` bracket
// syntax is just a branch-name escape, orthogonal to `|`/`!` kind. Orisha
// predates `BranchKind` and was kind-blind, silently accepting `| [pattern]`.
// This pins that the transform is now kind-aware and rejects `|` loudly.
~import orisha
~import std/io
const std = @import("std");
const TestRequest = struct {
method: []const u8,
path: []const u8,
};
const req = TestRequest{ .method = "GET", .path = "/" };
// `|` here is WRONG — these are dispatch handlers, must be `!`.
~orisha:router(req: &req)
| [GET /] |> std/io:print.ln("matched GET /")
| [*] |> std/io:print.ln("catch-all")
Actual compiler output
[ROUTER TRANSFORM] Found 2 pattern branches
[ROUTER TRANSFORM] profile: none (orisha.profile absent) — pattern order unchanged
[ROUTER TRANSFORM] Generated inline dispatch:
//@koru:inline_stmt
comptime { @compileError("orisha:router pattern branches must use effect `!`, not terminal `|`. Write `! [GET /path]` instead."); }
[ROUTER TRANSFORM] Generated handler-lite dispatch (1 routes):
//@koru:inline_stmt
if (std.mem.eql(u8, method, "GET") and std.mem.eql(u8, path, "/")) {
(struct { fn __kout(__fd: i32, __b: []const u8) void { if (@import("builtin").os.tag == .freestanding) { const __kc = struct { extern var stdout: ?*anyopaque; extern var stderr: ?*anyopaque; extern fn fputs(__s: [*:0]const u8, __st: ?*anyopaque) c_int; }; var __kt: [4096]u8 = undefined; for (0..(__b.len + __kt.len - 2) / (__kt.len - 1)) |__ki| { const __kn = @min(__kt.len - 1, __b.len - __ki * (__kt.len - 1)); @memcpy(__kt[0..__kn], __b[__ki * (__kt.len - 1)..][0..__kn]); __kt[__kn] = 0; @import("std").mem.doNotOptimizeAway(__kc.fputs(@as([*:0]const u8, @ptrCast(&__kt)), if (__fd == 2) __kc.stderr else __kc.stdout)); } } else { @import("std").mem.doNotOptimizeAway(@import("std").posix.write(__fd, __b) catch @as(usize, 0)); } } fn __kw(comptime __f: []const u8, __a: anytype) void { var __kb: [65536]u8 = undefined; const __ks = @import("std").fmt.bufPrint(&__kb, __f, __a) catch __kb[0..0]; __kout(1, __ks); } }).__kw("matched GET /\n", .{});
}
return null;
Error: install
+- install output
+- compile exe output Debug native 1 errors
output_emitted.zig:134:20: error: orisha:router pattern branches must use effect `!`, not terminal `|`. Write `! [GET /path]` instead.
comptime { @compileError("orisha:router pattern branches must use effect `!`, not terminal `|`. Write `! [GET /path]` instead."); }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
main: output_emitted.zig:9066:22
callMain [inlined]: .zig-cache/koru_lib_overlay/std/start.zig:618:22
callMainWithArgs [inlined]: .zig-cache/koru_lib_overlay/std/start.zig:587:20
main: .zig-cache/koru_lib_overlay/std/start.zig:602:28
1 reference(s) hidden; use '-freference-trace=5' to see all references
error: the following command failed with 1 compilation errors:
/opt/homebrew/Cellar/zig/0.15.2_1/bin/zig build-exe -lz -I/opt/homebrew/Cellar/openssl@3/3.6.4/include -L/opt/homebrew/Cellar/openssl@3/3.6.4/lib -lssl -I/opt/homebrew/Cellar/openssl@3/3.6.4/include -L/opt/homebrew/Cellar/openssl@3/3.6.4/lib -lcrypto -ODebug -I /opt/homebrew/opt/openssl@3/include -L /opt/homebrew/opt/openssl@3/lib --dep ast -Mroot=/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/350_SUBFLOWS/350_013_orisha_router_rejects_terminal/output_emitted.zig -ODebug --dep errors --dep glob_pattern_matcher -Mast=/Users/larsde/src/koru/src/ast.zig -ODebug -Merrors=/Users/larsde/src/koru/src/errors.zig -ODebug -Mglob_pattern_matcher=/Users/larsde/src/koru/src/glob_pattern_matcher.zig -lc --cache-dir .zig-cache --global-cache-dir /Users/larsde/.cache/zig --name output --zig-lib-dir .zig-cache/koru_lib_overlay/ --listen=-
Build Summary: 0/3 steps succeeded; 1 failed
install transitive failure
+- install output transitive failure
+- compile exe output Debug native 1 errors
error: the following build command failed with exit code 1:
.zig-cache/o/4b8df7f8b754ae0ba8ff803c6e3d7239/build /opt/homebrew/Cellar/zig/0.15.2_1/bin/zig .zig-cache/koru_lib_overlay /Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/350_SUBFLOWS/350_013_orisha_router_rejects_terminal .zig-cache /Users/larsde/.cache/zig --seed 0xe051183a -Z7abec729028327fb -Doptimize=DebugMust contain:
orisha:router pattern branches must use effectFlows
flow ~router click a branch to expand · @labels scroll to their anchor
router (req: &req)
Test Configuration
MUST_ERROR
koru.json:
{
"name": "router_showcase",
"version": "0.1.0",
"paths": {
"std": "../../../../../koru_std",
"orisha": "../../../../../../orisha/lib"
}
}