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:
agra
2026-06-06 02:51:09 +03:00
parent 3edc67521b
commit 9274d47adf
9 changed files with 110 additions and 4 deletions

View File

@@ -0,0 +1,26 @@
// Regression (issue 0100 F1): a QUALIFIED imported function that calls a
// function from its OWN flat import.
//
// `calc :: #import …` registers `calc.compute` as a module-qualified alias
// with a unique FuncId (the identity fix that resolves the cross-module
// same-name `parse` collision, issue 0100 / example 0719). That alias is
// lowered through `lazyLowerFunction`'s null-FuncId `lowerFunction` path,
// which has no declared `Function.source_file` to restore. Before the fix it
// lowered `calc.compute`'s body in the CALLER's (this file's) visibility
// context, so `compute`'s calls to `triple` / `base` — visible only from
// calc.sx's own `#import "util.sx"` — were rejected "not visible". The fix
// carries the alias's declaring source so it lowers in calc.sx's context.
#import "modules/std.sx";
calc :: #import "0720-modules-qualified-own-import/calc.sx";
report :: (label: string, ok: bool) {
if ok { print("{}: ok\n", label); } else { print("{}: FAIL\n", label); }
}
main :: () -> s32 {
// 14 * 3 = 42, computed by calc.compute -> triple(base()), both of which
// live in calc.sx's own flat import.
report("qualified-own-import", calc.compute() == 42);
0
}

View File

@@ -0,0 +1,8 @@
// `calc` is pulled in under a QUALIFIED namespace by the consumer
// (`calc :: #import …`), yet its own body calls `triple` / `base` from
// calc.sx's OWN flat `#import "util.sx"`. The qualified alias `calc.compute`
// must lower in calc.sx's source context so those own-import callees stay
// visible — issue 0100 F1.
#import "util.sx";
compute :: () -> s64 { return triple(base()); }

View File

@@ -0,0 +1,2 @@
triple :: (x: s64) -> s64 { return x * 3; }
base :: () -> s64 { return 14; }

View File

@@ -0,0 +1 @@
0

View File

@@ -0,0 +1 @@

View File

@@ -0,0 +1 @@
qualified-own-import: ok