✓
Passing This code compiles and runs correctly.
Code
// Test: a transform tor carried inside an imported module fires because the
// import landed it in the program tree — the entry never writes the
// invocation. `koru_std/ccp.kz`'s top-level `~tap(* -> *)` is this shape in
// production; this pins it for an arbitrary user-defined transform, which is
// the mechanism ambient Source-block handling (std/refine-style) rides on.
//
// Structure:
// test_lib/mymod.k → defines `install` transform + a top-level
// `install(mymod)` invocation that fires at Stage C
// and self-dissolves.
// input.k → imports the module, then prints at runtime.
//
// Expected: Stage C output carries `mymod install fired` (expected_comptime);
// runtime prints `entry ran` — the install flow left no residue.
import app/test_lib/mymod
import std/io
std/io:print.ln("entry ran")
Supporting Files
// Self-invoking transform module. The top-level `install(mymod)` flow is a
// transform SITE: the pass runner walks module_decl items, matches this
// invocation against the `install` transform entry, and fires it at Stage C.
// It must self-replace — a declined SiteResult only removes top-level flows,
// never one nested in a module_decl, so an empty return would leave a dead
// runtime call to `mymod:install` in the emitted program. `expr` is a
// required call input, so the self-invocation passes a token argument.
// `expr` is the only call input the site supplies; `item` is the transform
// ABI handle. `allocator`/`reporter`/`program` are omitted — the ABI binds
// params by name, and `std.mem.Allocator` cannot be spelled in a `.k`
// signature anyway (no host lines).
[comptime|transform]pub tor install {
expr: Expression,
item: *const std/compiler:Item
} -> SiteResult
proc install|zig {
const std = @import("std");
const ast = @import("ast");
_ = expr;
const flow = if (item.* == .flow)
&item.flow
else
return .{};
std.debug.print("mymod install fired\n", .{});
return .{ .replacement = ast.Item{ .inline_code = ast.InlineCode{
.code = "// install dissolved",
.location = flow.location,
.module = flow.module,
} } };
}
install(mymod)
Actual
entry ran
Expected output
entry ran
Expected comptime output
mymod install firedFlows
flow ~print.ln click a branch to expand · @labels scroll to their anchor
print.ln (expr: "entry ran")
Test Configuration
MUST_RUN