✓
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 |> _
Error Verification
Actual Compiler Output
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:9413:17: 0x1023ea4af 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:9497:28: 0x1023eb2b7 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[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 = d };
}
// Generic processor constrained to owned OR borrowed ONLY
~pub event process { d: *Data[M'owned|borrowed] }
| done *Data[M'owned|borrowed]
~proc process {
return .{ .done = d };
}
// Generic processor constrained to owned OR borrowed ONLY
~pub event process { data: *Data[M'owned|borrowed] }
| done *Data[M'owned|borrowed]
~proc process {
return .{ .done = data };
}
Test Configuration
MUST_FAIL