diff --git a/src/ir/lower.zig b/src/ir/lower.zig index ed82ab9..25513b3 100644 --- a/src/ir/lower.zig +++ b/src/ir/lower.zig @@ -8730,6 +8730,29 @@ pub const Lowering = struct { const saved_defer_base = self.func_defer_base; const saved_block_terminated = self.block_terminated; const saved_target = self.target_type; + // Pack-fn mono state is lexical to the pack-fn body. A generic + // function called from inside a pack-fn mono (e.g. + // `build(args: []Type, $ret: Type)` invoked from + // `probe(..$args) { build($args, void) }`) must not inherit the + // caller's pack maps — `lowerFieldAccess`'s `.len` + // intercept would otherwise constant-fold the callee's + // same-named param to whichever shape triggered the first mono + // and bake the wrong arity into the cached IR. Same shape of + // fix as `lazyLowerFunction` (issue-0048, commit 0ede097). + const saved_pan = self.pack_arg_nodes; + const saved_ppc = self.pack_param_count; + const saved_pat = self.pack_arg_types; + const saved_iri = self.inline_return_target; + self.pack_arg_nodes = null; + self.pack_param_count = null; + self.pack_arg_types = null; + self.inline_return_target = null; + defer { + self.pack_arg_nodes = saved_pan; + self.pack_param_count = saved_ppc; + self.pack_arg_types = saved_pat; + self.inline_return_target = saved_iri; + } self.func_defer_base = self.defer_stack.items.len; self.block_terminated = false;