✓
Passing This code compiles and runs correctly.
Code
// Test 164: Cross-Module Type Reference (Nested Modules)
//
// Tests referencing a type from an explicitly imported nested module.
// Module imports must be explicit - importing a directory does NOT
// automatically load subdirectories.
//
// Structure:
// test_lib/
// domain/
// user.kz -> defines DomainUser struct
//
// Key Test: Explicit import of nested module, then use its types/events.
const std = @import("std");
// Must explicitly import the nested module (using 'domain' alias from koru.json)
~import "$domain/user"
// This event uses a type from an explicitly imported nested module
~pub event grant_access {
user_data: domain.user:DomainUser,
}
| granted { success: bool }
~proc grant_access {
std.debug.print("Granting access: {s} as {s} (perms: {d})\n",
.{user_data.email, user_data.role, user_data.permissions});
return .{ .granted = .{ .success = true }};
}
// Create a domain user and grant access
~domain.user:create(email: "admin@example.com", role: "administrator", permissions: 999)
| created c |> grant_access(user_data: c.user)
| granted _ |> _
Expected Output
Granting access: admin@example.com as administrator (perms: 999)
Imported Files
// Nested domain user module
const std = @import("std");
// Define a domain-specific user type
pub const DomainUser = struct {
email: []const u8,
role: []const u8,
permissions: u32,
};
// Event that creates a domain user
~pub event create {
email: []const u8,
role: []const u8,
permissions: u32,
}
| created { user: DomainUser }
~proc create {
const new_user = DomainUser{
.email = email,
.role = role,
.permissions = permissions,
};
return .{ .created = .{ .user = new_user }};
}
Test Configuration
MUST_RUN