New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PATCH] Propagate lvalue context only to children of list ops which are not in void context. #11577
Comments
From gerard@ggoossen.netThis is a bug report for perl from gerard@ggoossen.net, From b6d8ec44ecd2370b1cbebf8e0ea399594475cd7d Mon Sep 17 00:00:00 2001 Children list ops might be in void context because the list is in scalar op.c | 7 ++++++- Inline Patchdiff --git a/op.c b/op.c
index 3d16001..3f5313d 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 c6a0a9a..87045fc 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 );
+}
--
Flags: Site configuration information for perl 5.15.1: Configured by gerard at Sun Aug 14 12:21:38 CEST 2011. Summary of my perl5 (revision 5 version 15 subversion 1) configuration: Locally applied patches: @INC for perl 5.15.1: Environment for perl 5.15.1: |
From @cpansproutOn Sun Aug 14 03:45:20 2011, ggoossen wrote:
While I’m not necessarily opposed to this change, it does remove some |
The RT System itself - Status changed from 'new' to 'open' |
From @cpansproutOn Sun Aug 14 14:25:15 2011, sprout wrote:
Actually, on second thought, I’m all for this change. There is no such |
From @cpansproutOn Mon Aug 15 14:54:18 2011, sprout wrote:
And I’ve just applied it as 5c90603. Thank you. |
@cpansprout - Status changed from 'open' to 'resolved' |
Migrated from rt.perl.org#96942 (status was 'resolved')
Searchable as RT96942$
The text was updated successfully, but these errors were encountered: