diff options
author | Father Chrysostomos <sprout@cpan.org> | 2011-06-23 09:44:45 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2011-06-23 10:23:45 -0700 |
commit | 4bee03f8e20d4e5257132fdea9f9fac4206c79f8 (patch) | |
tree | 622f6406d363cda9f90958b6698c272ffac4c41a /t | |
parent | 0accd0eeebd92a8877c7f7ecc13c7cb3ec364faa (diff) | |
download | perl-4bee03f8e20d4e5257132fdea9f9fac4206c79f8.tar.gz |
Fix explicit return of pad var in list lv context
This is something that commit e08be60 missed, though it never worked
properly, even in 5.14, as explicit return from lvalue subs used to
copy return values.
As the commit message for e08be60 states, returning a scalar itself
from an lvalue sub does not work if it is a pad variable with a refer-
ence count of 1, because the sub-popping code clears it on exit.
The one code path that did not account for this was list lvalue con-
text (real lvalue context, not just potentially lvalue). The only
observable effect this has is that assigning to a magic pad variable
returned from a subroutine in list context will not trigger set-magic.
This commit fixes it and also adds tests for returned magic pad vars
in all combinations of list/scalar lvalue/ref context.
Diffstat (limited to 't')
-rw-r--r-- | t/op/sub_lval.t | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/t/op/sub_lval.t b/t/op/sub_lval.t index 06ac461417..64e7b4edcc 100644 --- a/t/op/sub_lval.t +++ b/t/op/sub_lval.t @@ -3,7 +3,7 @@ BEGIN { @INC = '../lib'; require './test.pl'; } -plan tests=>167; +plan tests=>175; sub a : lvalue { my $a = 34; ${\(bless \$a)} } # Return a temporary sub b : lvalue { ${\shift} } @@ -556,6 +556,30 @@ is($@, "", "element of tied array"); is ($Tie_Array::val[0], "value"); +# Check that tied pad vars that are returned can be assigned to +sub TIESCALAR { bless [] } +sub STORE {$wheel = $_[1]} +sub FETCH {$wheel} +sub tied_pad_var :lvalue { tie my $tyre, ''; $tyre } +sub tied_pad_varr :lvalue { tie my $tyre, ''; return $tyre } +tied_pad_var = 1; +is $wheel, 1, 'tied pad var returned in scalar lvalue context'; +tied_pad_var->${\sub{ $_[0] = 2 }}; +is $wheel, 2, 'tied pad var returned in scalar ref context'; +(tied_pad_var) = 3; +is $wheel, 3, 'tied pad var returned in list lvalue context'; +$_ = 4 for tied_pad_var; +is $wheel, 4, 'tied pad var returned in list ref context'; +tied_pad_varr = 5; +is $wheel, 5, 'tied pad var explicitly returned in scalar lvalue context'; +tied_pad_varr->${\sub{ $_[0] = 6 }}; +is $wheel, 6, 'tied pad var explicitly returned in scalar ref context'; +(tied_pad_varr) = 7; +is $wheel, 7, 'tied pad var explicitly returned in list lvalue context'; +$_ = 8 for tied_pad_varr; +is $wheel, 8, 'tied pad var explicitly returned in list ref context'; + + # Test explicit return of lvalue expression { # subs are copies from tests 1-~18 with an explicit return added. |