From 1ffdc07ca785ef0cec11dad494fa4b9670382300 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Mon, 30 May 2011 18:45:26 -0700 Subject: [PATCH] Make explicit return in lvalue subs work under recursion This is something that fa1e92c missed. --- pp_ctl.c | 2 +- t/op/sub_lval.t | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pp_ctl.c b/pp_ctl.c index 16386a8..4780ead 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 a2b3c22..28d6763 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 -- 2.7.4