If a bare block is the last thing in an lvalue sub, OP_LEAVELOOP needs
to propagate lvalue context and handle returned arrays properly, just
as OP_LEAVE has done since yesterday.
This is a follow-up to
2ec7f6f24289. This came up in ticket #119797.
aelem helem aslice hslice padsv padav padhv enteriter entersub
padrange pushmark);
$priv{$_}{64} = "REFC" for qw(leave leavesub leavesublv leavewrite);
-$priv{leave}{128} = "LV";
+$priv{$_}{128} = "LV" for qw(leave leaveloop);
@{$priv{aassign}}{32,64} = qw(STATE COMMON);
@{$priv{sassign}}{32,64,128} = qw(STATE BKWARD CV2GV);
$priv{$_}{64} = "RTIME" for qw(match subst substcont qr);
break;
case OP_LEAVE:
+ case OP_LEAVELOOP:
o->op_private |= OPpLVALUE;
case OP_SCOPE:
case OP_ENTER:
/* Private for OP_LEAVE, OP_LEAVESUB, OP_LEAVESUBLV and OP_LEAVEWRITE */
#define OPpREFCOUNTED 64 /* op_targ carries a refcount */
-/* Private for OP_LEAVE only */
+/* Private for OP_LEAVE and OP_LEAVELOOP */
#define OPpLVALUE 128 /* Do not copy return value */
/* Private for OP_AASSIGN */
newsp = PL_stack_base + cx->blk_loop.resetsp;
TAINT_NOT;
- SP = adjust_stack_on_leave(newsp, SP, MARK, gimme, 0, FALSE);
+ SP = adjust_stack_on_leave(newsp, SP, MARK, gimme, 0,
+ PL_op->op_private & OPpLVALUE);
PUTBACK;
POPLOOP(cx); /* Stack values are safe: release loop vars ... */
@INC = '../lib';
require './test.pl';
}
-plan tests=>201;
+plan tests=>203;
sub a : lvalue { my $a = 34; ${\(bless \$a)} } # Return a temporary
sub b : lvalue { ${\shift} }
eval { (unless119797(0)) = 4..6 };
is $@, "", '$@ after writing to array returned by unless';
is "@119797", "4 5 6", 'writing to array returned by unless';
+sub bare119797 : lvalue {
+ {;
+ @119797
+ }
+}
+@119797 = ();
+eval { (bare119797(0)) = 4..6 };
+is $@, "", '$@ after writing to array returned by bare block';
+is "@119797", "4 5 6", 'writing to array returned by bare block';