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

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