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:
@@ -11324,8 +11324,12 @@ pub const Lowering = struct {
|
||||
if (!p.is_comptime) {
|
||||
// Contextually type the arg from the param (so a lambda arg
|
||||
// `(x) => …` takes its param types from a `Closure(...)` param).
|
||||
// The param type is resolved under the pack fn's OWN source
|
||||
// (E4): a fixed-prefix type bare-visible only in the defining
|
||||
// module must resolve there, not the caller's. The arg itself
|
||||
// is lowered AFTER, in the caller's context.
|
||||
const saved_tt = self.target_type;
|
||||
const pty = self.resolveParamType(&p);
|
||||
const pty = self.resolveParamTypeInSource(fd.body.source_file, &p);
|
||||
if (pty != .unresolved) self.target_type = pty;
|
||||
args.append(self.alloc, self.lowerExpr(call_node.args[ri])) catch return self.builder.constInt(0, .void);
|
||||
self.target_type = saved_tt;
|
||||
@@ -11634,7 +11638,12 @@ pub const Lowering = struct {
|
||||
ct_arg_idx += 1;
|
||||
continue;
|
||||
}
|
||||
const pty = self.resolveParamType(&p);
|
||||
// Pin to the pack fn's OWN module (E4): a fixed-prefix param whose
|
||||
// type is bare-visible only in the defining module must resolve
|
||||
// there, not in the caller's restored context. Mirrors the
|
||||
// signature build above and `resolveParamTypeInSource` at the
|
||||
// cross-module call-arg typing sites.
|
||||
const pty = self.resolveParamTypeInSource(fd.body.source_file, &p);
|
||||
const slot = self.builder.alloca(pty);
|
||||
self.builder.store(slot, Ref.fromIndex(param_idx));
|
||||
scope.put(p.name, .{ .ref = slot, .ty = pty, .is_alloca = true });
|
||||
|
||||
Reference in New Issue
Block a user