This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #119797] Fix if/else in lvalue sub
authorFather Chrysostomos <sprout@cpan.org>
Thu, 24 Oct 2013 03:21:04 +0000 (20:21 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 24 Oct 2013 03:21:04 +0000 (20:21 -0700)
commit2ec7f6f24289a5b511edf35181d0178b1e94b0f3
tree432c4b46efdac9dd1f93ae3da73041d503df79f6
parent4c3ed7418bcf4eae5235fb7bcae842820725bea8
[perl #119797] Fix if/else in lvalue sub

When if/else/unless is the last thing in an lvalue sub, the lvalue
context is not always propagated properly and scope exit tries to
copy things, including arrays, resulting in ‘Bizarre copy of ARRAY’.

This commit fixes the bizarre copy by flagging any leave op that is
part of an lvalue sub’s return sequence, using the OPpLEAVE flag added
for this purpose in the previous commit.  Then pp_leave uses that flag
to avoid copying return values, but protects them via the mortals
stack just like pp_leavesublv (actually pp_ctl.c:S_return_lvalues).

For ‘if’ and ‘unless’ without ‘else’, the lvalue context was not being
propagated, resulting in arrays’ getting flattened despite the lvalue
context.  op_lvalue_flags in op.c needed to handle AND and OR ops,
which ‘if’ and ‘unless’ compile to, to make this work.
embed.fnc
embed.h
op.c
pp_ctl.c
proto.h
t/op/sub_lval.t