Commit d6a285f4d5 for perl
commit d6a285f4d5002817f0fa811032032ee381c51d21
Author: Paul Evans <leonerd@leonerd.org.uk>
Date: Wed Nov 18 21:09:05 2026 +0000
Put fresh variables in optional named parameters for each call
Fixes [GH#25054]
diff --git a/pp.c b/pp.c
index e0118cec57..aa0719678c 100644
--- a/pp.c
+++ b/pp.c
@@ -8756,11 +8756,12 @@ PP(pp_paramtest)
PP_wrapped(pp_paramstore, 1, 0)
{
dSP;
- dTARGET;
SV *value = POPs;
+ SV **padentry = &PAD_SVl(PL_op->op_targ);
- SvPADSTALE_off(TARG);
- SvSetMagicSV(TARG, value);
+ save_clearsv(padentry);
+ SvPADSTALE_off(*padentry);
+ SvSetMagicSV(*padentry, value);
RETURN;
}
diff --git a/t/op/signatures.t b/t/op/signatures.t
index b3a9756b98..e3fd68b45b 100644
--- a/t/op/signatures.t
+++ b/t/op/signatures.t
@@ -1006,6 +1006,17 @@ is eval("tnamed07(w => 'W', x => 'X', y => 'Y', z => 'Z')"), "x=X y=Y";
is $tnamed11->(x => 123, y => 456, z => 789), "x=123 y=456 <z 789>";
}
+# Named params are assigned to fresh variables (GH#25054)
+{
+ sub tnamed12 (:$x) { return sub { $x++ }; }
+ is join("", map { $_->() } map { tnamed12(x => 0) } 1 .. 5), "00000",
+ 'Mandatory named parameters get fresh variables on each call';
+
+ sub tnamed13 (:$x = 0) { return sub { $x++ }; }
+ is join("", map { $_->() } map { tnamed13() } 1 .. 5), "00000",
+ 'Optional named parameters get fresh variables on each call';
+}
+
sub t085
(
$