state variable constrained accepts

✓ Passing This code compiles and runs correctly.

Code

// Test 523: Constrained state variable accepts valid states
// Tests that M'owned|borrowed accepts both owned and borrowed
//
// Key points:
// - data:process has d: *Data[M'owned|borrowed]
// - M is constrained to ONLY owned OR borrowed
// - [owned] should be accepted, M = owned
// - [borrowed] should be accepted, M = borrowed
// - Output preserves the specific state that was passed

~import "$app/data"

// Test 1: Constraint accepts [owned]
~app.data:alloc()
| allocated a |> app.data:process(d: a.data)  // M'owned|borrowed accepts [owned], M = owned
    | done _ |> _  // d.d: *Data[owned] - preserved!
input.kz

Imported Files

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

~pub event alloc {}
| allocated { data: *Data[owned] }

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

~pub event borrow { other: *Data[owned] }
| borrowed { data: *Data[borrowed] }

~proc borrow {
    return .{ .borrowed = .{ .data = other } };
}

// Generic processor constrained to owned OR borrowed
// Will NOT accept other states like "gc" or "static"
~pub event process { d: *Data[M'owned|borrowed] }
| done { d: *Data[M'owned|borrowed] }  // Preserves whichever state was passed

~proc process {
    return .{ .done = .{ .d = d } };
}
data.kz
// Generic processor constrained to owned OR borrowed
// Will NOT accept other states like "gc" or "static"

~pub event process { data: *Data[M'owned|borrowed] }
| done { data: *Data[M'owned|borrowed] }  // Preserves whichever state was passed

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