sv_2mortal(*newsp);
}
else
- *++newsp = *SP;
+ *++newsp =
+ (!CxLVAL(cx) || CxLVAL(cx) & OPpENTERSUB_INARGS) &&
+ !SvTEMP(*SP)
+ ? sv_2mortal(SvREFCNT_inc_simple_NN(*SP))
+ : *SP;
}
else
*++newsp = &PL_sv_undef;
}
else if (gimme == G_ARRAY) {
assert (!(CxLVAL(cx) & OPpENTERSUB_DEREF));
- while (++MARK <= SP) {
+ if (!CxLVAL(cx) || CxLVAL(cx) & OPpENTERSUB_INARGS)
+ while (++MARK <= SP)
+ *++newsp =
+ SvTEMP(*MARK)
+ ? *MARK
+ : sv_2mortal(SvREFCNT_inc_simple_NN(*MARK));
+ else while (++MARK <= SP) {
*++newsp = *MARK;
TAINT_NOT; /* Each item is independent */
}
sv_2mortal(*MARK);
}
else
- *MARK = TOPs;
+ *MARK = SvTEMP(TOPs)
+ ? TOPs
+ : sv_2mortal(SvREFCNT_inc_simple_NN(TOPs));
}
else {
MEXTEND(MARK, 0);
}
SP = MARK;
}
+ else if (gimme == G_ARRAY) {
+ rvalue_array:
+ for (MARK = newsp + 1; MARK <= SP; MARK++) {
+ if (!SvTEMP(*MARK))
+ *MARK = sv_2mortal(SvREFCNT_inc_simple_NN(*MARK));
+ }
+ }
}
if (CxLVAL(cx) & OPpENTERSUB_DEREF) {
}
}
- rvalue_array:
PUTBACK;
LEAVE;
@INC = '../lib';
require './test.pl';
}
-plan tests=>151;
+plan tests=>155;
sub a : lvalue { my $a = 34; ${\(bless \$a)} } # Return a temporary
sub b : lvalue { ${\shift} }
is join('-',%$_), '4-5', '%{func()} autovivification'.$suffix;
}
continue { $suffix = ' (explicit return)' }
+
+# [perl #92406] [perl #92290] Returning a pad var in rvalue context
+$suffix = '';
+for my $sub (
+ sub :lvalue { my $x = 72; $x },
+ sub :lvalue { my $x = 72; return $x }
+) {
+ is scalar(&$sub), 72, "sub returning pad var in scalar context$suffix";
+ is +(&$sub)[0], 72, "sub returning pad var in list context$suffix";
+}
+continue { $suffix = ' (explicit return)' }