summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2011-05-30 20:43:03 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-05-30 20:43:03 -0700
commitb724cc14b25929aee44eee20bd26102cceb520b6 (patch)
tree130ca4b63ef6121587ae7a829822cfb2f03fd022
parentf6a9f8a45e0553298d2b10c734f5826f1ba7730f (diff)
downloadperl-b724cc14b25929aee44eee20bd26102cceb520b6.tar.gz
Allow returning of temps and ro’s from lv subs
This commit removes the restriction on returning temps and read-only scalars from lvalue subs that occurs when the sub returns implicitly (with no ‘return’ statement; ‘return’ has never had that restriction). It does not actually help pure-Perl lvalue subs much yet, as op.c still enforces lvalue syntax on the last statement. But this should fix bug #71172, allowing XS lvalue subs to work under the debugger.
-rw-r--r--pp_hot.c21
-rw-r--r--t/op/sub_lval.t4
2 files changed, 4 insertions, 21 deletions
diff --git a/pp_hot.c b/pp_hot.c
index 04de368d18..9730af74f5 100644
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -2725,27 +2725,10 @@ PP(pp_leavesublv)
MARK = newsp + 1;
EXTEND_MORTAL(1);
if (MARK == SP) {
- /* Temporaries are bad unless they happen to have set magic
- * attached, such as the elements of a tied hash or array */
- if ((SvFLAGS(TOPs) & (SVs_TEMP | SVs_PADTMP) ||
- (SvFLAGS(TOPs) & (SVf_READONLY | SVf_FAKE))
- == SVf_READONLY
- ) &&
- !SvSMAGICAL(TOPs)) {
- LEAVE;
- cxstack_ix--;
- POPSUB(cx,sv);
- PL_curpm = newpm;
- LEAVESUB(sv);
- DIE(aTHX_ "Can't return %s from lvalue subroutine",
- SvREADONLY(TOPs) ? (TOPs == &PL_sv_undef) ? "undef"
- : "a readonly value" : "a temporary");
- }
- else { /* Can be a localized value
- * subject to deletion. */
+ /* Can be a localized value
+ * subject to deletion. */
PL_tmps_stack[++PL_tmps_ix] = *mark;
SvREFCNT_inc_void(*mark);
- }
}
else { /* Should not happen? */
LEAVE;
diff --git a/t/op/sub_lval.t b/t/op/sub_lval.t
index c87b4840b9..6aa516b749 100644
--- a/t/op/sub_lval.t
+++ b/t/op/sub_lval.t
@@ -218,7 +218,7 @@ eval <<'EOE' or $_ = $@;
1;
EOE
-like($_, qr/Can't return undef from lvalue subroutine/);
+like($_, qr/Modification of a read-only value attempted/);
sub lv10 : lvalue {}
@@ -238,7 +238,7 @@ eval <<'EOE' or $_ = $@;
1;
EOE
-like($_, qr/Can't return undef from lvalue subroutine/);
+like($_, qr/Modification of a read-only value attempted/);
$_ = undef;
eval <<'EOE' or $_ = $@;