state variable constraint violation

✓ Passing This code compiles and runs correctly.

Code

// MUST_FAIL
// EXPECT: State variable constraint violation
//
// Test 524: Constrained state variable REJECTS invalid state
// Tests that M'owned|borrowed REJECTS states not in the constraint
//
// Key points:
// - data:process has d: *Data[M'owned|borrowed]
// - M is constrained to ONLY owned OR borrowed
// - [gc] is NOT in the constraint
// - Should fail at compile time with constraint violation error

~import "$app/data"

// ERROR: [gc] not in constraint M'owned|borrowed
~app.data:gc_alloc()
| allocated a |> app.data:process(d: a.data)  // ❌ ERROR: [gc] doesn't satisfy M'owned|borrowed
    | done |> _
input.kz

Error Verification

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 (29 items)
[PHASE 2.6] Rescanning transformed AST (29 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[KORU030]: branch 'done' has payload but no binding
  --> structural_check:17:0

❌ Compiler coordination error: Incomplete branch coverage
error: CompilerCoordinationFailed
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/524_state_variable_constraint_violation/backend.zig:9407:17: 0x1002c6433 in emit (backend)
                return error.CompilerCoordinationFailed;
                ^
/Users/larsde/src/koru/tests/regression/300_ADVANCED_FEATURES/330_PHANTOM_TYPES/524_state_variable_constraint_violation/backend.zig:9491:28: 0x1002c71bf in main (backend)
    const generated_code = try RuntimeEmitter.emit(compile_allocator, final_ast);
                           ^

Imported Files

const std = @import("std");
const Data = struct { value: i32 };

~pub event gc_alloc {}
| allocated { data: *Data[gc] }  // GC-managed, NOT owned or borrowed

~proc gc_alloc {
    const allocator = std.heap.page_allocator;
    const d = allocator.create(Data) catch unreachable;
    d.* = Data{ .value = 42 };
    return .{ .allocated = .{ .data = d } };
}

// Generic processor constrained to owned OR borrowed ONLY
~pub event process { d: *Data[M'owned|borrowed] }
| done { d: *Data[M'owned|borrowed] }

~proc process {
    return .{ .done = .{ .d = d } };
}
data.kz
// Generic processor constrained to owned OR borrowed ONLY

~pub event process { data: *Data[M'owned|borrowed] }
| done { data: *Data[M'owned|borrowed] }

~proc process {
    return .{ .done = .{ .data = data } };
}
processor.kz

Test Configuration

MUST_FAIL