diff --git a/examples/0739-modules-comptime-pack-arg-caller-context.sx b/examples/0739-modules-comptime-pack-arg-caller-context.sx new file mode 100644 index 0000000..3a84c3e --- /dev/null +++ b/examples/0739-modules-comptime-pack-arg-caller-context.sx @@ -0,0 +1,25 @@ +// Caller-owned helpers passed as VARIADIC comptime-pack args (`..$args`) to a +// NAMESPACED imported metaprogram resolve in the CALLER's visibility context — +// not the metaprogram's defining module (regression, issue 0106 follow-up). +// +// `std.print :: ($fmt: string, ..$args)` is authored in `std.sx`; the pack args +// `caller_num()` / `caller_two()` are authored HERE in the caller. The body's +// typed `args[i]` substitution (via packArgNodeAt) lowers each pack arg under +// the metaprogram's defining-module pin, so without stamping the pack-arg nodes +// with the caller's source, the bare names `caller_num` / `caller_two` were +// wrongly checked against `std.sx` and rejected as "not visible". The fixed +// comptime param (`$fmt`) already got this treatment; this extends it to every +// node in the variadic pack. The metaprogram's OWN code (build_format / out) +// still resolves in `std.sx`, so the defining-context pin stays intact. +// +// Two pack positions lock that EVERY pack arg is stamped, not just the first. +// s64 values only — accepted by print at runtime today (no 0107/0108 coupling). +std :: #import "modules/std.sx"; + +caller_num :: () -> s64 { return 42; } +caller_two :: () -> s64 { return 7; } + +main :: () -> s32 { + std.print("{} {}\n", caller_num(), caller_two()); + return 0; +} diff --git a/examples/expected/0739-modules-comptime-pack-arg-caller-context.exit b/examples/expected/0739-modules-comptime-pack-arg-caller-context.exit new file mode 100644 index 0000000..573541a --- /dev/null +++ b/examples/expected/0739-modules-comptime-pack-arg-caller-context.exit @@ -0,0 +1 @@ +0 diff --git a/examples/expected/0739-modules-comptime-pack-arg-caller-context.stderr b/examples/expected/0739-modules-comptime-pack-arg-caller-context.stderr new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/expected/0739-modules-comptime-pack-arg-caller-context.stderr @@ -0,0 +1 @@ + diff --git a/examples/expected/0739-modules-comptime-pack-arg-caller-context.stdout b/examples/expected/0739-modules-comptime-pack-arg-caller-context.stdout new file mode 100644 index 0000000..1be21da --- /dev/null +++ b/examples/expected/0739-modules-comptime-pack-arg-caller-context.stdout @@ -0,0 +1 @@ +42 7 diff --git a/src/ir/lower.zig b/src/ir/lower.zig index f281079..4d0a488 100644 --- a/src/ir/lower.zig +++ b/src/ir/lower.zig @@ -9631,6 +9631,17 @@ pub const Lowering = struct { if (param.is_comptime and call_arg_idx <= call_node.args.len) { pack_arg_name = param.name; pack_arg_slice = call_node.args[call_arg_idx..]; + // Stamp each pack arg with the caller's source so the + // body's typed `args[i]` substitution (via packArgNodeAt, + // lowered under the defining-module pin set below) resolves + // its bare names in the CALLER's visibility context — the + // same treatment the fixed comptime params get below. + // Without it a caller-owned helper passed to an imported + // metaprogram (`std.print("{}", caller_fn())`) resolves + // under the callee's module and is reported "not visible". + for (call_node.args[call_arg_idx..]) |pack_arg| { + self.stampCallerSource(pack_arg); + } } break; // variadic is always the last param }