Make explicit return in lvalue subs work under recursion
authorFather Chrysostomos <sprout@cpan.org>
Tue, 31 May 2011 01:45:26 +0000 (18:45 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Tue, 31 May 2011 01:45:26 +0000 (18:45 -0700)
This is something that fa1e92c missed.

pp_ctl.c
t/op/sub_lval.t

index 16386a8..4780ead 100644 (file)
--- 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);
index a2b3c22..28d6763 100644 (file)
@@ -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