✓
Passing This code compiles and runs correctly.
Code
// Test 167: Import Depth Limit Enforcement (MUST_FAIL)
//
// Tests that import paths are limited to 2 segments after the alias.
// This enforces good architectural design by forcing extraction of
// deeply nested paths into their own koru.json aliases.
//
// Maximum allowed depth:
// ✅ ~import "app" (0 segments)
// ✅ ~import "app/module" (1 segment)
// ✅ ~import "app/module/sub" (2 segments)
// ❌ ~import "app/a/b/c" (3 segments - TOO DEEP!)
//
// Expected: PARSE003 error with helpful message about extracting to koru.json
const std = @import("std");
// This import has 3 segments after $app and should FAIL
~import app/test_lib/net/tcp
~event test {}
~proc test|zig {
std.debug.print("Test: optional parent\n", .{});
}
// Use submodule (no parent exists, that's OK!)
~app/test_lib/net/tcp:connect(host: "localhost", port: 8080)
| connected |> std/io:print.ln("TCP connected!")
| failed |> std/io:print.ln("TCP failed")
// Run test
~test()
Must fail at frontend compile:
Parsing or type-checking must reject the program.
Expected compiler error
error[PARSE003]: import path too deep: 'app/test_lib/net/tcp' has 3 segments after alias (max: 2)
To fix: add a new alias to koru.json, e.g.:
"paths": { "mylib": "./path/to/lib" }
Then use: ~import "mylib/..." (Suggested: extract 'app' as its own alias)
--> tests/regression/100_MODULE_SYSTEM/110_IMPORTS/110_016_optional_parent/input.kz:18:1
|
18 | ~import app/test_lib/net/tcp
| ^
Error Verification
Expected Error Pattern
This test demonstrates the import depth limit enforcement.
Import paths are limited to maximum 2 segments after the alias:
✅ ~import "$alias"
✅ ~import "$alias/module"
✅ ~import "$alias/module/submodule"
❌ ~import "$alias/a/b/c" (TOO DEEP!)
The error message suggests extracting deeply nested paths as their own aliases in koru.json.
Expected error: PARSE003 - import path too deepActual Compiler Output
error[PARSE003]: import path too deep: 'app/test_lib/net/tcp' has 3 segments after alias (max: 2)
To fix: add a new alias to koru.json, e.g.:
"paths": { "mylib": "./path/to/lib" }
Then use: ~import "mylib/..." (Suggested: extract 'app' as its own alias)
--> tests/regression/100_MODULE_SYSTEM/110_IMPORTS/110_016_optional_parent/input.kz:18:1
|
18 | ~import app/test_lib/net/tcp
| ^Imported Files
// TCP module for test_lib.net
// Note: No parent net.kz file exists - this tests that parent is optional
const std = @import("std");
~pub event connect { host: []const u8, port: u16 }
~proc connect|zig {
std.debug.print("Attempting TCP connection to {s}:{d}\n", .{host, port});
// Simulate connection failure for test
}
Test Configuration
MUST_FAIL