This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix several array-returning bugs in lvalue subs
authorFather Chrysostomos <sprout@cpan.org>
Sat, 4 Jun 2011 13:44:01 +0000 (06:44 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 4 Jun 2011 13:44:01 +0000 (06:44 -0700)
commit40c94d11f196fbff790bdeedf21d0c2c8896eb52
tree90481d8ab12bc244f42916d2a7830f19d74fe4bc
parente77205b98539352eb52fa99101772539f332bf03
Fix several array-returning bugs in lvalue subs

This finishes fixing bug #23790.

When called in reference context (for(...) or map $_, ...), lvalue
subs returning arrays or hashes would return the AV or HV itself, as
though it were lvalue context.

The result was that $_ would be bound to an AV or HV, which is not
supposed to happen, as it’s a scalar (that’s when you start getting
‘Bizarre copy’ errors).

Commit 91e34d82 fixed this in pp_leavesublv, but the if condition it
added was placed outside the loop, so it only applied when the array
was the first thing returned. It also did not take hashes into account.

By changing the lvalue-context check in pp_padav, pp_padhv and
pp_rv2av (which also serves as pp_rv2hv), I was able to apply a more
general fix, which also fix another bug: Those array and hash ops were
croaking when called in scalar reference context (...->$method).

Because it is no longer part of the sub-leaving code, explicitly
returning an array in reference context works now, too.

This commit also eliminates the code added by 91e34d82, as it’s no
longer necessary.
pp.c
pp_hot.c
t/op/sub_lval.t