lang: fn aliases dispatch like their target (fix 0121) — scan-time registration through the shared alias-chain walk
Renamed fn aliases failed for EVERY kind (the filed pack-only scope was a same-name confound: same-name re-exports already resolved through the name-keyed fn_ast_map). scanDecls now follows ident-/ns.X-RHS const alias chains (aliasedFnDecl; 0120's hop walk extracted as followAliasChain) and registers the alias name in fn_ast_map (absent-only), so every dispatch path — early pack/comptime/generic, plain lazy-lower, plan-side typing — sees the target decl unchanged. my_print :: s.print; / my_format :: s.format; now work (the std.sx re-export shape). Regression: examples/0546 (+rich). Gates: zig build test 0, suite 588/588.
This commit is contained in:
@@ -211,8 +211,7 @@ pub fn checkRequiredEntryPoints(self: *Lowering) void {
|
||||
}
|
||||
|
||||
if (self.diagnostics) |diags| {
|
||||
diags.addFmt(.err, null,
|
||||
"target is Android but no `#jni_main` Activity declared. " ++
|
||||
diags.addFmt(.err, null, "target is Android but no `#jni_main` Activity declared. " ++
|
||||
"The OS launches a Java-side Activity that delegates lifecycle " ++
|
||||
"callbacks into sx — declare one like:\n\n" ++
|
||||
" Bundle :: #foreign #jni_class(\"android/os/Bundle\") {{ }}\n\n" ++
|
||||
@@ -366,8 +365,7 @@ pub fn detectContextDecl(decls: []const *const Node) bool {
|
||||
for (decls) |decl| {
|
||||
const found = switch (decl.data) {
|
||||
.struct_decl => |sd| std.mem.eql(u8, sd.name, "Context"),
|
||||
.const_decl => |cd|
|
||||
std.mem.eql(u8, cd.name, "Context") and cd.value.data == .struct_decl,
|
||||
.const_decl => |cd| std.mem.eql(u8, cd.name, "Context") and cd.value.data == .struct_decl,
|
||||
.namespace_decl => |ns| detectContextDecl(ns.decls),
|
||||
else => false,
|
||||
};
|
||||
@@ -596,30 +594,48 @@ pub fn scanDecls(self: *Lowering, decls: []const *const Node) void {
|
||||
}
|
||||
}
|
||||
self.putTypeAlias(self.current_source_file, cd.name, target_ty);
|
||||
} else if (cd.value.data == .identifier) {
|
||||
// Identifier-RHS alias: MyAlias :: MyInt; WideAlias :: Wide.
|
||||
// SOURCE-AWARE (E1.5). Resolve the RHS `B` AS SEEN FROM this
|
||||
// alias's OWN source via `selectNominalLeaf` (E1's source-
|
||||
// keyed nominal leaf), NEVER the global `type_alias_map` /
|
||||
// global `findByName` (last-wins across modules). Only the
|
||||
// `.resolved` outcome is written; `.pending` (B is itself a
|
||||
// forward alias not resolved yet), `.undeclared`, and
|
||||
// `.not_visible` (a same-name B authored only by a namespaced
|
||||
// import) leave A UNWRITTEN so the source-aware
|
||||
// `resolveForwardIdentifierAliases` fixpoint re-tries A once
|
||||
// the local B registers. A GLOBAL selection here would bind A
|
||||
// to a namespaced same-name B, and the per-source fixpoint
|
||||
// guard (`aliasResolvedInSource`) would then SKIP A — leaving
|
||||
// the wrong global TypeId and re-opening 0105 one layer down
|
||||
// (R1, E1.5). Same unified `putTypeAlias` writer (no-drift).
|
||||
const rhs = cd.value.data.identifier;
|
||||
} else if (cd.value.data == .identifier or cd.value.data == .field_access) {
|
||||
// FN alias (issue 0121): `print2 :: print;` /
|
||||
// `my_print :: s.print;`. When the alias chain terminates
|
||||
// at a fn decl, register the ALIAS name in `fn_ast_map`
|
||||
// pointing at the target's decl — every dispatch path
|
||||
// (early pack/comptime/generic, plain lazy-lower,
|
||||
// plan-side return typing) reads that map, so the alias
|
||||
// dispatches exactly like the target. Absent-only: a real
|
||||
// same-name fn keeps its slot (same-name re-exports are
|
||||
// a no-op — the target already owns the name).
|
||||
if (self.current_source_file orelse self.main_file) |from| {
|
||||
switch (self.selectNominalLeaf(rhs.name, from, rhs.is_raw)) {
|
||||
.resolved => |tid| self.putTypeAlias(self.current_source_file, cd.name, tid),
|
||||
// `.ambiguous` (same-name RHS authored by ≥2 flat
|
||||
// imports) leaves A unwritten like `.not_visible`;
|
||||
// the loud diagnostic fires where A is USED.
|
||||
.pending, .forward, .undeclared, .not_visible, .ambiguous => {},
|
||||
if (self.aliasedFnDecl(&decl.data.const_decl, from)) |target_fd| {
|
||||
if (!self.program_index.fn_ast_map.contains(cd.name)) {
|
||||
self.program_index.fn_ast_map.put(cd.name, target_fd) catch {};
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cd.value.data == .identifier) {
|
||||
// Identifier-RHS alias: MyAlias :: MyInt; WideAlias :: Wide.
|
||||
// SOURCE-AWARE (E1.5). Resolve the RHS `B` AS SEEN FROM this
|
||||
// alias's OWN source via `selectNominalLeaf` (E1's source-
|
||||
// keyed nominal leaf), NEVER the global `type_alias_map` /
|
||||
// global `findByName` (last-wins across modules). Only the
|
||||
// `.resolved` outcome is written; `.pending` (B is itself a
|
||||
// forward alias not resolved yet), `.undeclared`, and
|
||||
// `.not_visible` (a same-name B authored only by a namespaced
|
||||
// import) leave A UNWRITTEN so the source-aware
|
||||
// `resolveForwardIdentifierAliases` fixpoint re-tries A once
|
||||
// the local B registers. A GLOBAL selection here would bind A
|
||||
// to a namespaced same-name B, and the per-source fixpoint
|
||||
// guard (`aliasResolvedInSource`) would then SKIP A — leaving
|
||||
// the wrong global TypeId and re-opening 0105 one layer down
|
||||
// (R1, E1.5). Same unified `putTypeAlias` writer (no-drift).
|
||||
const rhs = cd.value.data.identifier;
|
||||
if (self.current_source_file orelse self.main_file) |from| {
|
||||
switch (self.selectNominalLeaf(rhs.name, from, rhs.is_raw)) {
|
||||
.resolved => |tid| self.putTypeAlias(self.current_source_file, cd.name, tid),
|
||||
// `.ambiguous` (same-name RHS authored by ≥2 flat
|
||||
// imports) leaves A unwritten like `.not_visible`;
|
||||
// the loud diagnostic fires where A is USED.
|
||||
.pending, .forward, .undeclared, .not_visible, .ambiguous => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -686,7 +702,7 @@ pub fn scanDecls(self: *Lowering, decls: []const *const Node) void {
|
||||
// template via the namespace edge (mirrors the annotation
|
||||
// head site `resolveParameterizedWithBindings`), not the
|
||||
// bare last-wins `struct_template_map`.
|
||||
const pt_alias: ?[]const u8 = if (pt_qualified) pt.name[0 .. std.mem.indexOfScalar(u8, pt.name, '.').?] else null;
|
||||
const pt_alias: ?[]const u8 = if (pt_qualified) pt.name[0..std.mem.indexOfScalar(u8, pt.name, '.').?] else null;
|
||||
// Generic-struct alias base: route layout selection through the
|
||||
// single choke-point (CP-1); the builtin parameterised-type
|
||||
// path (Vector etc.) stays as the non-generic fall-through.
|
||||
@@ -1669,7 +1685,9 @@ pub fn selectNominalLeaf(self: *Lowering, name: []const u8, from: []const u8, ra
|
||||
else => self.namedRefTid(fa.raw, name),
|
||||
};
|
||||
if (fa_tid) |t| {
|
||||
if (found_tid) |f| { if (t != f) return .ambiguous; } else found_tid = t;
|
||||
if (found_tid) |f| {
|
||||
if (t != f) return .ambiguous;
|
||||
} else found_tid = t;
|
||||
} else {
|
||||
flat_has_unregistered = true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user