summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerard Goossen <gerard@ggoossen.net>2011-08-13 18:38:13 +0200
committerFather Chrysostomos <sprout@cpan.org>2011-08-15 20:27:01 -0700
commit5c906035ffb6b2857a0f941a97ac9e7bb4126275 (patch)
tree1207023797ece7e334d596be0a38f272bf596734
parentc192154b7b5060196110d20f17b18135fa216641 (diff)
downloadperl-5c906035ffb6b2857a0f941a97ac9e7bb4126275.tar.gz
Propagate lvalue context only to children of list ops which are not in void context.
Children list ops might be in void context because the list is in scalar context. A test that discarded elements in a list are not assigned lvalue context is added. Children of a list op might also be in void context because they are special entersub ops for attributes. This patch makes the OPpENTERSUB_NOMOD flag redundant.
-rw-r--r--op.c7
-rw-r--r--t/op/list.t9
2 files changed, 14 insertions, 2 deletions
diff --git a/op.c b/op.c
index 775705b55e..c4c0e76249 100644
--- a/op.c
+++ b/op.c
@@ -1718,6 +1718,8 @@ Perl_op_lvalue_flags(pTHX_ OP *o, I32 type, U32 flags)
return o;
}
+ assert( (o->op_flags & OPf_WANT) != OPf_WANT_VOID );
+
switch (o->op_type) {
case OP_UNDEF:
localize = 0;
@@ -2016,7 +2018,10 @@ Perl_op_lvalue_flags(pTHX_ OP *o, I32 type, U32 flags)
case OP_LIST:
localize = 0;
for (kid = cLISTOPo->op_first; kid; kid = kid->op_sibling)
- op_lvalue(kid, type);
+ /* elements might be in void context because the list is
+ in scalar context or because they are attribute sub calls */
+ if ( (kid->op_flags & OPf_WANT) != OPf_WANT_VOID )
+ op_lvalue(kid, type);
break;
case OP_RETURN:
diff --git a/t/op/list.t b/t/op/list.t
index c6a0a9a98f..87045fcbd5 100644
--- a/t/op/list.t
+++ b/t/op/list.t
@@ -6,7 +6,7 @@ BEGIN {
}
require "test.pl";
-plan( tests => 63 );
+plan( tests => 64 );
@foo = (1, 2, 3, 4);
cmp_ok($foo[0], '==', 1, 'first elem');
@@ -175,3 +175,10 @@ cmp_ok(join('',(1,2),3,(4,5)),'eq','12345','list (..).(..)');
my @b = qw();
is($#b, -1);
}
+
+{
+ # comma operator with lvalue only propagates the lvalue context to
+ # the last operand.
+ ("const", my $x) ||= 1;
+ is( $x, 1 );
+}