✓
Passing This code compiles and runs correctly.
Code
// TEST: Pass a Transaction where Connection is expected (WITHOUT --strict-base-types)
//
// Without --strict-base-types, Koru only checks phantom states.
// Zig's actual type system catches the mismatch during compilation.
//
// This is the DEFAULT behavior and is MORE ACCURATE than Koru's
// string-based type comparison because Zig handles:
// - Type aliases (const Conn = Connection)
// - Module-qualified types correctly
// - All the nuances of its own type system
//
// close() expects: *Connection[!active]
// We're passing: *Transaction[active!]
//
// Koru phantom checker passes (both have [active] state)
// Zig type checker fails (Transaction != Connection)
~import "$app/db"
~app.db:connect(host: "localhost")
| ok c |>
app.db:begin(conn: c.conn)
| ok t |>
// BUG: Passing t.tx (*Transaction) to close() which expects *Connection
// Koru won't catch this without --strict-base-types
// Zig WILL catch this during compilation
app.db:close(conn: t.tx)
|> _
| 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 { conn: *Connection[active!] }
| err { msg: []const u8 }
~proc connect {
const c = std.heap.page_allocator.create(Connection) catch unreachable;
c.* = Connection{ .handle = 42 };
return .{ .ok = .{ .conn = 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 { tx: *Transaction[active!] }
| err { msg: []const u8 }
~proc begin {
const tx = std.heap.page_allocator.create(Transaction) catch unreachable;
tx.* = Transaction{ .handle = conn.handle };
std.heap.page_allocator.destroy(conn);
return .{ .ok = .{ .tx = tx } };
}
// close: consumes *Connection[!active]
// This should ONLY accept Connection, NOT Transaction!
~[!]pub event close { conn: *Connection[!active] }
~proc close {
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 {
std.debug.print("COMMIT (handle={})\n", .{tx.handle});
std.heap.page_allocator.destroy(tx);
}
Test Configuration
Expected Error:
expected type '*output_emitted.koru_app.db.Connection', found '*output_emitted.koru_app.db.Transaction'