FAQ
# New Ticket Created by Gerard Goossen
# Please include the string: [perl #96942]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=96942 >



This is a bug report for perl from gerard@ggoossen.net,
generated with the help of perlbug 1.39 running under perl 5.15.1.
From b6d8ec44ecd2370b1cbebf8e0ea399594475cd7d Mon Sep 17 00:00:00 2001
From: Gerard Goossen <gerard@ggoossen.net>
Date: Sat, 13 Aug 2011 18:38:13 +0200
Subject: [PATCH] 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.
---
op.c | 7 ++++++-
t/op/list.t | 9 ++++++++-
2 files changed, 14 insertions(+), 2 deletions(-)

diff --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 );
+}
--
1.7.5.4

---
Flags:
category=core
severity=low
---
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:
Commit id: 699e6d637d01cb2033f3acfaf1d8ad76daf1227b
Platform:
osname=linux, osvers=2.6.39-2-686-pae, archname=i686-linux
uname='linux zeus 2.6.39-2-686-pae #1 smp tue jul 5 03:48:49 utc 2011 i686 gnulinux '
config_args='-des -DDEBUGGING -Doptimize=-O3 -g3 -Dusedevel -Dprefix=/home/gerard/perl/inst/blead-codegen'
hint=recommended, useposix=true, d_sigaction=define
useithreads=undef, usemultiplicity=undef
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler:
cc='cc', ccflags ='-DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O3 -g3',
cppflags='-DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
ccversion='', gccversion='4.6.1', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries:
ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib /usr/lib/i386-linux-gnu /usr/lib64
libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
libc=, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.13'
Dynamic Linking:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fPIC', lddlflags='-shared -O3 -g3 -L/usr/local/lib -fstack-protector'

Locally applied patches:


---
@INC for perl 5.15.1:
lib
/home/gerard/perl/inst/blead-codegen/lib/site_perl/5.15.1/i686-linux
/home/gerard/perl/inst/blead-codegen/lib/site_perl/5.15.1
/home/gerard/perl/inst/blead-codegen/lib/5.15.1/i686-linux
/home/gerard/perl/inst/blead-codegen/lib/5.15.1
/home/gerard/perl/inst/blead-codegen/lib/site_perl
.

---
Environment for perl 5.15.1:
HOME=/home/gerard
LANG=en_US.UTF-8
LANGUAGE (unset)
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/home/gerard/bin:/usr/local/bin:/usr/bin:/bin:/usr/games
PERL_BADLANG (unset)
SHELL=/bin/bash

Search Discussions

  • Father Chrysostomos via RT at Aug 14, 2011 at 9:25 pm

    On Sun Aug 14 03:45:20 2011, ggoossen wrote:
    +{
    + # comma operator with lvalue only propagates the lvalue context
    to
    + # the last operand.
    + ("const", my $x) ||= 1;
    + is( $x, 1 );
    +}
    While I’m not necessarily opposed to this change, it does remove some
    error-checking. I’m just bringing it up, in case others want to comment.
  • Father Chrysostomos via RT at Aug 15, 2011 at 9:54 pm

    On Sun Aug 14 14:25:15 2011, sprout wrote:
    On Sun Aug 14 03:45:20 2011, ggoossen wrote:
    +{
    + # comma operator with lvalue only propagates the lvalue context
    to
    + # the last operand.
    + ("const", my $x) ||= 1;
    + is( $x, 1 );
    +}
    While I’m not necessarily opposed to this change, it does remove some
    error-checking. I’m just bringing it up, in case others want to comment.
    Actually, on second thought, I’m all for this change. There is no such
    thing as void lvalue context, so if parts of perl think there is, that’s
    just a bug.
  • Father Chrysostomos via RT at Aug 16, 2011 at 3:28 am

    On Mon Aug 15 14:54:18 2011, sprout wrote:
    On Sun Aug 14 14:25:15 2011, sprout wrote:
    On Sun Aug 14 03:45:20 2011, ggoossen wrote:
    +{
    + # comma operator with lvalue only propagates the lvalue context
    to
    + # the last operand.
    + ("const", my $x) ||= 1;
    + is( $x, 1 );
    +}
    While I’m not necessarily opposed to this change, it does remove some
    error-checking. I’m just bringing it up, in case others want to comment.
    Actually, on second thought, I’m all for this change. There is no such
    thing as void lvalue context, so if parts of perl think there is, that’s
    just a bug.
    And I’ve just applied it as 5c906035ff. Thank you.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupperl5-porters @
categoriesperl
postedAug 14, '11 at 10:45a
activeAug 16, '11 at 3:28a
posts4
users1
websiteperl.org

1 user in discussion

Father Chrysostomos via RT: 4 posts

People

Translate

site design / logo © 2022 Grokbase