fix(lower): qualified alias lowers in its own source context [0100 F1]
The 0100 identity fix registers a namespaced import's own functions under a module-qualified name (ns.fn) in fn_ast_map WITHOUT an eager declareFunction, so the alias is lowered through lazyLowerFunction's null-FuncId lowerFunction path. That path had no Function.source_file to restore (the non-null path does setCurrentSourceFile(func.source_file)), so the alias lowered in the CALLER's visibility context. A qualified function that called a helper from its OWN module's flat import was then rejected "not visible". Fix: - ProgramIndex.qualified_fn_source maps each ns.fn alias to its declaring source file, populated in registerQualifiedFn (current_source_file is pinned to the decl's source by registerNamespaceQualifiedFns). - lazyLowerFunction's null-FuncId branch restores that source before lowerFunction, so ns.fn's body lowers in its own module's context and its intra-module / own-import callees resolve. - lowerFunction records Function.source_file = current_source_file on the freshly-begun function (matching declareFunction), so the lowered alias carries its own module for diagnostics/emit. Regression: examples/0720-modules-qualified-own-import.sx — calc.compute (a qualified alias) calls triple/base from calc.sx's own flat import; reports "'triple' is not visible" on the attempt-1 code, passes after. 0719's cross-module dual-parse assertion stays green. issues/0100 RESOLVED banner extended with the F1 follow-up.
This commit is contained in:
@@ -591,6 +591,14 @@ pub const ProgramIndex = struct {
|
||||
// ── Declaration maps ──
|
||||
/// Function name → AST decl.
|
||||
fn_ast_map: std.StringHashMap(*const ast.FnDecl),
|
||||
/// Module-qualified function name (`ns.fn`) → its declaring source file.
|
||||
/// A qualified alias is registered in `fn_ast_map` WITHOUT an eager
|
||||
/// `declareFunction`, so `lazyLowerFunction` lowers it through the
|
||||
/// null-FuncId `lowerFunction` path with no `Function.source_file` to
|
||||
/// restore. This carries the alias's OWN module source so its body lowers
|
||||
/// in the right visibility context — its intra-module / own-import callees
|
||||
/// resolve (issue 0100 F1). Keyed/allocated with the lowering allocator.
|
||||
qualified_fn_source: std.StringHashMap([]const u8),
|
||||
/// sx alias → ForeignClassDecl (jni_class / objc_class / swift_class / ... — registered in scan pass).
|
||||
foreign_class_map: std.StringHashMap(*const ast.ForeignClassDecl) = std.StringHashMap(*const ast.ForeignClassDecl).init(std.heap.page_allocator),
|
||||
/// `#run` global name → GlobalId.
|
||||
@@ -613,6 +621,7 @@ pub const ProgramIndex = struct {
|
||||
return .{
|
||||
.import_flags = std.StringHashMap(bool).init(alloc),
|
||||
.fn_ast_map = std.StringHashMap(*const ast.FnDecl).init(alloc),
|
||||
.qualified_fn_source = std.StringHashMap([]const u8).init(alloc),
|
||||
.global_names = std.StringHashMap(GlobalInfo).init(alloc),
|
||||
};
|
||||
}
|
||||
@@ -621,6 +630,7 @@ pub const ProgramIndex = struct {
|
||||
// Owned maps only — module_scopes / import_graph are borrowed.
|
||||
self.import_flags.deinit();
|
||||
self.fn_ast_map.deinit();
|
||||
self.qualified_fn_source.deinit();
|
||||
self.foreign_class_map.deinit();
|
||||
self.global_names.deinit();
|
||||
self.type_alias_map.deinit();
|
||||
|
||||
Reference in New Issue
Block a user