✓
Passing This code compiles and runs correctly.
Code
// Cross-target effect-branch dispatch: MULTIPLE effect kinds, multi-fire.
//
// `tokenize` yields two distinct effect kinds — `! token` and `! warning` —
// fired interleaved by the producer. Each kind dispatches to its own handler;
// the synthesized Handlers struct must compose both handler-fns and route each
// call site to the right one. This is the vaxis/Orisha pump shape (cf. the
// zig-only 400_073), now proven on BOTH targets.
//
// Output goes through a per-target `report` proc (std.debug.print | console.log)
// so we never touch print.blk/print.ln (zig-only comptime transforms with no
// JS path). Handlers accumulate counts into module vars; report prints them.
//
// NOTE on arg names: the JS inline-plain-handler path resolves dispatch args
// by FIELD-name match, so the punned dispatch arg's name must equal the target
// event's field name (onToken's field is `t`, dispatched as `onToken(t)`). The
// case where they differ is a real JS-emitter gap, pinned separately by
// 400_112_effect_branch_arg_name_mismatch_cross_target.
pub event tokenize { n: u64 }
! token u64
! warning u64
pub event onToken { t: u64 }
pub event onWarning { w: u64 }
pub event report {}
tokenize(n: 5)
! token t |> onToken(t)
! warning w |> onWarning(w)
report()
Actual
tokens=5 warnings=3 sum=10
Expected output
✓ Zig✓ JavaScripttokens=5 warnings=3 sum=10
Emitted JavaScript source
let tokens = 0;
let warnings = 0;
let token_sum = 0;
const main_module = {
tokenize_event: {
handler(input, H) {
const token = H.token;
const warning = H.warning;
const n = input.n;
for (let i = 0; i < n; i++) {
token(i);
if (i % 2 == 0) {
warning(i);
}
}
},
},
onToken_event: {
handler(input) {
const t = input.t;
tokens = tokens + 1; token_sum = token_sum + t;
},
},
onWarning_event: {
handler(input) {
const w = input.w;
warnings = warnings + 1;
},
},
report_event: {
handler(input) {
console.log("tokens=" + tokens + " warnings=" + warnings + " sum=" + token_sum);
},
},
flow0() {
const __arg_0 = 5;
{
const n = __arg_0;
for (let i = 0; i < n; i++) {
{
const t = i;
{
tokens = tokens + 1; token_sum = token_sum + t;
}
}
if (i % 2 == 0) {
{
const w = i;
{
warnings = warnings + 1;
}
}
}
} }
},
flow1() {
{
console.log("tokens=" + tokens + " warnings=" + warnings + " sum=" + token_sum);
}
},
};
main_module.flow0();
main_module.flow1();
Test Configuration
MUST_RUN