✓
Passing This code compiles and runs correctly.
Code
// TEST: Pass a Transaction where Connection is expected
//
// CRITICAL: Both types have IDENTICAL struct layout (just i32 handle)
// AND both have the SAME phantom state name [active!]
//
// close() expects: *Connection[!active]
// We're passing: *Transaction[active!]
//
// If Koru's phantom checker only looks at state names,
// this will COMPILE AND RUN - which is WRONG!
//
// The phantom type system MUST check base types.
~import "$app/db"
// BUG: the `| ok t |> app.db:close(conn: t)` handler below passes t
// (*Transaction) to close() which expects *Connection. Both have [active]
// state and the same struct layout — only the type name differs. Koru MUST
// catch this.
~app.db:connect(host: "localhost")
| ok c |> app.db:begin(conn: c)
| ok t |> app.db:close(conn: t)
| err _ |> _
| err _ |> _
Imported Files
// Database module with Connection and Transaction as IDENTICAL struct layout
// Both have phantom states with the SAME NAME
// The ONLY difference is the semantic TYPE NAME
const std = @import("std");
// BOTH are structurally identical - just an i32 handle!
const Connection = struct { handle: i32 };
const Transaction = struct { handle: i32 }; // Same layout as Connection!
// connect: produces *Connection[active!]
~pub event connect { host: []const u8 }
| ok *Connection[active!]
| err []const u8
~proc connect|zig {
const c = std.heap.page_allocator.create(Connection) catch unreachable;
c.* = Connection{ .handle = 42 };
return .{ .ok = c };
}
// begin: consumes *Connection[!active], produces *Transaction[active!]
// NOTE: Transaction also has [active!] - same state name as Connection!
~pub event begin { conn: *Connection[!active] }
| ok *Transaction[active!]
| err []const u8
~proc begin|zig {
const tx = std.heap.page_allocator.create(Transaction) catch unreachable;
tx.* = Transaction{ .handle = conn.handle };
std.heap.page_allocator.destroy(conn);
return .{ .ok = tx };
}
// close: consumes *Connection[!active]
// This should ONLY accept Connection, NOT Transaction!
~[!]pub event close { conn: *Connection[!active] }
~proc close|zig {
std.debug.print("Connection closed (handle={})\n", .{conn.handle});
std.heap.page_allocator.destroy(conn);
}
// commit: consumes *Transaction[!active]
// This should ONLY accept Transaction, NOT Connection!
~[!]pub event commit { tx: *Transaction[!active] }
~proc commit|zig {
std.debug.print("COMMIT (handle={})\n", .{tx.handle});
std.heap.page_allocator.destroy(tx);
}
Test Configuration
Compiler Flags:
--strict-base-typesExpected Error:
error[KORU030]: Type mismatch: expected 'app.db:*Connection[!active]' but got 'app.db:*Transaction[app.db:active!]' for argument 'conn'