Files
sx/examples/0544-packs-imported-pack-fn-fixed-param-source-pin/lib.sx
agra a250964ced 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.
2026-06-08 11:52:23 +03:00

17 lines
740 B
Plaintext

// `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];