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.
23 lines
1.1 KiB
Plaintext
23 lines
1.1 KiB
Plaintext
// 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;
|
|
}
|