○
Planned This feature is planned but not yet implemented.
OWED: when-clause sits at the call site (pinned emit pattern).
Failure Output
Showing last 10 of 25 lines
13 | |> _
| ^
hint: '_' has meaning only as `| branch [binding] |> _`. Outside a branch handler body — top-level void chain, split-pipeline tail — `|> _` is meaningless.
error[KORU010]: '_' is only legal as the body of a branch handler
--> tests/regression/400_RUNTIME_FEATURES/420_PERFORMANCE/915_when_at_callsite/input.kz:16:0
|
16 | |> _
| ^
hint: '_' has meaning only as `| branch [binding] |> _`. Outside a branch handler body — top-level void chain, split-pipeline tail — `|> _` is meaningless. Code
// Test 915: VERIFY when clause is at CALL SITE, not inside tap
//
// The ONLY way to verify this is to CHECK THE GENERATED CODE
// This test expects a specific pattern in output_emitted.zig
const std = @import("std");
~tor produce { value: u32 }
|> log(d.result)
|> _
~produce(value: 10)
|> _
~produce(value: 30)
|> _
Supporting Files
# BUG: When Clause Is Inside Tap Function, Should Be At Call Site
## Current (WRONG) Implementation:
```zig
fn __tap0(d: anytype) void {
if (d.result > 50) { // ← When clause INSIDE tap function
const nested_result_0 = alert.handler(.{ .result = d.result });
_ = nested_result_0;
}
}
// Call site
switch (result) {
.done => |_tap_payload| {
__tap0(_tap_payload); // ← Called unconditionally
// Terminal
},
}
```
## Correct Implementation Should Be:
```zig
fn __tap0(d: anytype) void {
// NO if statement here
const nested_result_0 = alert.handler(.{ .result = d.result });
_ = nested_result_0;
}
// Call site
switch (result) {
.done => |_tap_payload| {
if (_tap_payload.result > 50) { // ← When clause at CALL SITE
__tap0(_tap_payload);
}
// Terminal
},
}
```
## Why This Matters:
1. **Performance**: Condition should be checked BEFORE function call overhead
2. **Semantics**: The when clause filters which events fire taps, not what taps do
3. **Composability**: Tap functions should be pure - the filtering is a property of the observation, not the action
## How to Verify:
Check `output_emitted.zig` and search for `__tap0`. The `if` statement should be at the call site, not in the function body.
## Files to Fix:
- `/Users/larsde/src/koru/koru_std/compiler_bootstrap.kz` lines 1559-1564 (tap function generation)
- All tap injection sites need to emit the when clause check before calling tap
Expected output
Produced: 20
Produced: 60
Logging: 60
Test Configuration
MUST_RUN