summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-05-30 18:45:26 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-05-30 18:45:26 -0700
commit1ffdc07ca785ef0cec11dad494fa4b9670382300 (patch)
treecfcb218340f886f197de6730fcc50c2374d13854
parentb6d8be65ce3d63a311da4edee2288074a3750f05 (diff)
downloadperl-1ffdc07ca785ef0cec11dad494fa4b9670382300.tar.gz
Make explicit return in lvalue subs work under recursion
This is something that fa1e92c missed.
-rw-r--r--pp_ctl.c2
-rw-r--r--t/op/sub_lval.t13
2 files changed, 13 insertions, 2 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index 16386a83f1..4780ead2ac 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -2294,7 +2294,7 @@ PP(pp_return)
if (MARK < SP) {
if (popsub2) {
if (cx->blk_sub.cv && CvDEPTH(cx->blk_sub.cv) > 1) {
- if (SvTEMP(TOPs)) {
+ if (lval || SvTEMP(TOPs)) {
*++newsp = SvREFCNT_inc(*SP);
FREETMPS;
sv_2mortal(*newsp);
diff --git a/t/op/sub_lval.t b/t/op/sub_lval.t
index a2b3c2218a..28d67631ac 100644
--- a/t/op/sub_lval.t
+++ b/t/op/sub_lval.t
@@ -3,7 +3,7 @@ BEGIN {
@INC = '../lib';
require './test.pl';
}
-plan tests=>90;
+plan tests=>91;
sub a : lvalue { my $a = 34; ${\(bless \$a)} } # Return a temporary
sub b : lvalue { ${\shift} }
@@ -571,6 +571,17 @@ is ($Tie_Array::val[0], "value");
++bad_inc(bad_id1(bad_id(bad_get_lex)));
cmp_ok($in, '==', 25);
+
+ # Recursive
+ my $r;
+ my $to_modify;
+ $r = sub :lvalue {
+ my $depth = shift//0;
+ if ($depth == 2) { return $to_modify }
+ return &$r($depth+1);
+ };
+ &$r(0) = 7;
+ is $to_modify, 7, 'recursive lvalue sub';
}
{ # bug #23790