fix(0114): gate alias-qualified calls to one-level carry, pin to target

The lowerCall namespace branch routed alias.fn() through the global
qualified registration (first-wins) at any import depth, and through the
global last-wins bare map for comptime/generic members. Plain-identifier
alias roots now resolve via the carry-aware namespaceAliasVerdict:

- visible alias (own edge or ONE flat hop): the member dispatches the
  TARGET module's own fn (namespaceFnMember + fd-keyed bareAuthorFuncId),
  so two modules' same-named aliases each call their own target.
- two direct flat imports carrying the alias to distinct targets:
  loud ambiguity diagnostic.
- alias only reachable beyond one hop: "namespace 'X' is not visible".
- foreign / builtin / #compiler members keep the literal-symbol path.

Regressions: examples 0832 (two-hop), 0833 (carried collision),
0834 (own-target pin / first-wins repair).
This commit is contained in:
agra
2026-06-11 09:16:03 +03:00
parent 22552075d5
commit fbbfcb268c
26 changed files with 196 additions and 14 deletions

View File

@@ -708,6 +708,51 @@ pub fn lowerCall(self: *Lowering, c_in: *const ast.Call) Ref {
std.fmt.allocPrint(self.alloc, "{s}.{s}", .{ n, fa.field }) catch func_name
else
func_name;
// The carry gate (issue 0114): a plain-identifier root that is
// a namespace ALIAS (not a type / fn global name — those are
// the `Type.method` paths below) must be visible under the
// carry rule, and its fn members dispatch pinned to the
// alias's TARGET module — never the global first-wins
// qualified registration, never the last-wins bare fallback.
gate: {
if (fa.object.data != .identifier) break :gate;
const oname = fa.object.data.identifier.name;
if (self.program_index.global_names.contains(oname)) break :gate;
switch (self.namespaceAliasVerdict(oname)) {
.target => |target| {
const fd = Lowering.namespaceFnMember(&target, fa.field) orelse break :gate;
// Foreign / builtin / #compiler bodies keep their
// literal global symbol — the existing bare-name
// machinery below resolves them.
switch (fd.body.data) {
.foreign_expr, .builtin_expr, .compiler_expr => break :gate,
else => {},
}
if (hasComptimeParams(fd)) return self.lowerComptimeCall(fd, c);
if (fd.type_params.len > 0) return self.lowerGenericCall(fd, fa.field, c, args.items);
var sf = SelectedFunc{ .decl = fd, .source = target.target_module_path };
const fid = self.selectedFuncId(&sf, fa.field);
const func = &self.module.functions.items[@intFromEnum(fid)];
self.packVariadicCallArgs(fd, c, &args);
const final_args = self.prependCtxIfNeeded(func, args.items);
self.coerceCallArgs(final_args, func.params);
if (func.is_variadic) self.promoteCVariadicArgs(final_args, func.params.len);
return self.builder.call(fid, final_args, func.ret);
},
.ambiguous => {
if (self.diagnostics) |d|
d.addFmt(.err, fa.object.span, "namespace '{s}' is ambiguous: aliases from multiple flat-imported modules point at different targets; declare the alias locally", .{oname});
return Ref.none;
},
.none => {
if (self.aliasDeclaredAnywhere(oname)) {
if (self.diagnostics) |d|
d.addFmt(.err, fa.object.span, "namespace '{s}' is not visible; #import the module that declares it", .{oname});
return Ref.none;
}
},
}
}
// Check for comptime-expanded or generic functions (try both names)
const effective_name = if (self.program_index.fn_ast_map.get(qualified_name) != null) qualified_name else func_name;
if (self.program_index.fn_ast_map.get(effective_name)) |fd| {