diff options
author | Father Chrysostomos <sprout@cpan.org> | 2014-12-15 22:23:23 -0800 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2014-12-15 22:26:03 -0800 |
commit | 1e2dd519edd4fc9003c1fe08496c7c9b73d52b7e (patch) | |
tree | 21686411d86d558172720ccc96ad89aee350211a /t | |
parent | 9cef6114780c9135e573ee321ee9525d0f9ca414 (diff) | |
download | perl-1e2dd519edd4fc9003c1fe08496c7c9b73d52b7e.tar.gz |
[perl #123020] Scalar cx for lhs of void (...)x...
No sane code calls x in void context (except at the end of a subrou-
tine), but we have to handle it anyway.
Previously, the left-hand parenthesized operand to (...)x... would be
evaluated in the context in which the current sub was called. I.e.,
if the last statement in the current sub is called in last context,
then then lhs of (...)x... a hundred lines earlier (say we have a
big sub) is called in list context, even though it is completely
unrelated.
Since the left-hand operand could be called in any of the three con-
texts when x itself was in void context, I could choose whatever I
wanted when making it consistent. Scalar context makes the most sense
to me, because x falls back to string repeat when not in list context,
and because void context makes stack handling complex.
Unfortunately, this does not fix the context if x occurs at the end of
a subroutine. That will be a lot trickier to fix. (Hence, the com-
plex stack handling in pp_repeat must remain.)
Diffstat (limited to 't')
-rw-r--r-- | t/op/flip.t | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/t/op/flip.t b/t/op/flip.t index ea8c67d0be..2706bf82cf 100644 --- a/t/op/flip.t +++ b/t/op/flip.t @@ -5,7 +5,7 @@ BEGIN { require "./test.pl"; } -plan(13); +plan(14); @a = (1,2,3,4,5,6,7,8,9,10,11,12); @b = (); @@ -101,3 +101,9 @@ sub f { 13 5 EOT } + +# Void context gives parenthesized lhs scalar context +no warnings 'void'; +sub c { $context = qw[ void scalar list ][wantarray + defined wantarray] } +(c())x34; +is $context, 'scalar', '(...)x... in void context'; |