✓
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 { value: i32 }
| done { final: i32 }
~proc counter {
std.debug.print("Count: {}\n", .{n});
if (n < 3) {
return .{ .next = .{ .value = n + 1 } };
} else {
return .{ .done = .{ .final = 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
[PHASE 2.4] Calling run_pass for transforms\n[PHASE 2.5] Executing comptime_main() - running comptime flows
[PHASE 2.5] Comptime flows complete (33 items)
[PHASE 2.6] Rescanning transformed AST (33 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[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:9469:17: 0x1020ee433 in emit (backend)
return error.CompilerCoordinationFailed;
^
/Users/larsde/src/koru/tests/regression/000_CORE_LANGUAGE/040_CONTROL_FLOW/206_label_scope_errors/backend.zig:9553:28: 0x1020ef1bf in main (backend)
const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
^Test Configuration
MUST_FAIL