fix(stdlib/E4): source-pin pack-fn fixed-prefix param types to the defining module
E4's pack-fn source-pin was incomplete: an imported pack function's
fixed-prefix (non-pack) parameter types were resolved in the CALLER's
module, so a param whose type is bare-visible only in the pack fn's own
module was wrongly rejected with "type 'X' is not visible" — even though
the equivalent plain fn (typed via the source-pinned call-arg path) ran
fine.
Two sites in the pack-mono path re-resolved the fixed-prefix param type
in the caller's context:
- lowerPackFnCall: the call-site arg-typing pass (to contextually type
the arg from its param) — fires first.
- monomorphizePackFn: the body parameter binding, after the caller
source was restored from the signature build.
Both now resolve via resolveParamTypeInSource(fd.body.source_file, &p),
pinning to the pack fn's defining module — matching the already-pinned
signature build, the body lowering, and the cross-module call-arg typing
sites. The call-site arg itself is still lowered AFTER, in the caller's
context (issue 0106).
Regression: examples/0544-packs-imported-pack-fn-fixed-param-source-pin
(main -> lib -> dep; `Needs` two flat hops away, never named in main).
Fails pre-fix with "type 'Needs' is not visible"; passes after. A control
plain fn in the same lib already ran, isolating the pack-mono path.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
// Regression (stdlib E4): an imported pack function whose fixed-prefix param
|
||||
// type is visible only in its defining module must resolve during pack
|
||||
// monomorphization. `lib.sx` imports `dep.sx` (which defines `Needs`) and
|
||||
// exposes `make() -> Needs` plus `use_pack(n: Needs, ..$args)`. `main` imports
|
||||
// ONLY `lib.sx`, so `Needs` is two flat hops away and not bare-visible here —
|
||||
// main never names it.
|
||||
//
|
||||
// Before the fix, `monomorphizePackFn` restored the caller's source before
|
||||
// re-binding the fixed-prefix params, so `n: Needs` was resolved in main's
|
||||
// context and rejected with "type 'Needs' is not visible" — even though the
|
||||
// control plain fn `use_plain(n: Needs)` (typed via the source-pinned call-arg
|
||||
// path) ran fine. The fixed-prefix param is now resolved under the pack fn's own
|
||||
// source (`fd.body.source_file`), matching the rest of the pack signature/body.
|
||||
#import "modules/std.sx";
|
||||
#import "0544-packs-imported-pack-fn-fixed-param-source-pin/lib.sx";
|
||||
|
||||
main :: () -> s32 {
|
||||
x := make();
|
||||
print("plain {}\n", use_plain(x));
|
||||
print("pack {}\n", use_pack(x, 1, 2));
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
// `Needs` lives two flat-import hops away from `main` (main -> lib -> dep), so
|
||||
// it is NOT bare-visible at the call site under non-transitive visibility.
|
||||
Needs :: struct { v: s64; }
|
||||
@@ -0,0 +1,16 @@
|
||||
// `lib.sx` imports `dep.sx`, so `Needs` is bare-visible HERE. A module that
|
||||
// imports only `lib.sx` cannot see `Needs` (non-transitive). The pack fn's
|
||||
// fixed-prefix param `n: Needs` must therefore resolve in this module's
|
||||
// context, not the caller's.
|
||||
#import "modules/std.sx";
|
||||
#import "dep.sx";
|
||||
|
||||
make :: () -> Needs => Needs.{ v = 7 };
|
||||
|
||||
// Control: a plain (non-pack) fn with the same fixed param already resolves in
|
||||
// its defining module — the cross-module call-arg typing path is source-pinned.
|
||||
use_plain :: (n: Needs) -> s64 => n.v;
|
||||
|
||||
// Pack fn: the fixed-prefix param `n: Needs` is bound during pack
|
||||
// monomorphization. Its type must resolve under this module's source.
|
||||
use_pack :: (n: Needs, ..$args) -> s64 => n.v + args[0];
|
||||
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
plain 7
|
||||
pack 8
|
||||
Reference in New Issue
Block a user