✓
Passing This code compiles and runs correctly.
Code
// ============================================================================
// VERIFIED REGRESSION TEST - DO NOT MODIFY WITHOUT DISCUSSION
// ============================================================================
// Test 206: Label scope errors
// Tests that labels are flow-scoped and cannot be accessed across flows
// Expected to fail compilation with "Unknown label 'loop'" error
// ============================================================================
const std = @import("std");
// Simple counter event
~event counter { n: i32 }
| next i32
| done i32
~proc counter {
std.debug.print("Count: {}\n", .{n});
if (n < 3) {
return .{ .next = n + 1 };
} else {
return .{ .done = n };
}
}
// Start event
~event start {}
| ready
~proc start {
std.debug.print("Starting...\n", .{});
return .{ .ready = .{} };
}
// Flow 1 with a label
~start()
| ready |> #loop counter(n: 1)
| next c |> @loop(n: c.value)
| done |> _
// Flow 2 trying to jump to Flow 1's label (should error!)
~start()
| ready |> @loop(n: 1) // ERROR: 'loop' is not in scope here
Error Verification
Expected Error Pattern
Label Scope Validation Test
This test MUST FAIL to verify that labels are flow-scoped.
Expected behavior:
- Flow 1 defines label 'loop'
- Flow 2 tries to jump to 'loop' which is out of scope
- Shape checker should reject this with "Unknown label 'loop'"
This validates that label scope checking is working correctly in the backend.Actual Compiler Output
error[KORU041]: unknown label '@loop'
--> structural_check:44:0
❌ Compiler coordination error: Unknown label referenced
error: CompilerCoordinationFailed
/Users/larsde/src/koru/tests/regression/000_CORE_LANGUAGE/040_CONTROL_FLOW/206_label_scope_errors/backend.zig:9475:17: 0x100d924af in emit (backend)
return error.CompilerCoordinationFailed;
^
/Users/larsde/src/koru/tests/regression/000_CORE_LANGUAGE/040_CONTROL_FLOW/206_label_scope_errors/backend.zig:9559:28: 0x100d932b7 in main (backend)
const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
^Test Configuration
MUST_FAIL