This code:
my $x if ...; sub { $x}
could attempt to clone $x even if $x is stale.
p4raw-id: //depot/perl@31447
"Variable \"%s\" is not available", SvPVX_const(namesv));
sv = NULL;
}
- else {
- assert(!SvPADSTALE(sv));
+ /* 'my $x if $y' can leave $x stale even in an active sub */
+ else if (!SvPADSTALE(sv)) {
SvREFCNT_inc_simple_void_NN(sv);
}
}
use Config;
require './test.pl'; # for runperl()
-print "1..187\n";
+print "1..188\n";
my $test = 1;
sub test (&) {
test { $flag == 1 };
}
+# although the 'my $x if ...' form is deprecated, it must still work.
+# Ensure that cloning a stale var gives a new undef value rather than
+# sharing the old value
+
+{
+ sub f {
+ my $a = 1 if $_[0];
+ return sub { \$a };
+ }
+ my $c1 = f(1);
+ my $c2 = f(0);
+ my $r1 = $c1->();
+ my $r2 = $c2->();
+ warn "r1=$r1 r2=$r2\n";
+ test { !defined $$r2 };
+ test { $r1 ne $r2 };
+}
+