Skip Menu |
Report information
Id: 127333
Status: resolved
Priority: 0/
Queue: perl5

Owner: Nobody
Requestors: tonyc <tony [at] develop-help.com>
Cc:
AdminCc:

Operating System: All
PatchStatus: (no value)
Severity: low
Type: unknown
Perl Version: 5.23.6
Fixed In: (no value)



Subject: until( assignment ) doesn't warn when while (assignment ) does
Download (untitled) / with headers
text/plain 3.2k
This is similar to #127122, but doesn't have quite as simple a fix. $ ./perl -Ilib -Mwarnings=syntax -le 'while ($x = 0) { }' Found = in conditional, should be == at -e line 1. $ ./perl -Ilib -Mwarnings=syntax -le 'until ($x = 1) { }' $ $ ./perl -Ilib -V Summary of my perl5 (revision 5 version 23 subversion 8) configuration: Derived from: 08b3e84fbb1c493d7157c2ad8d1dec4242c965cc Platform: osname=linux, osvers=3.16.0-4-amd64, archname=x86_64-linux uname='linux mars 3.16.0-4-amd64 #1 smp debian 3.16.7-ckt20-1+deb8u2 (2016-01-02) x86_64 gnulinux ' config_args='-des -Dusedevel -Uversiononly -DDEBUGGING -Dprefix=/home/tony/perl/blead -Doptimize=-O0 -g3' hint=recommended, useposix=true, d_sigaction=define useithreads=undef, usemultiplicity=undef use64bitint=define, use64bitall=define, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2', optimize='-O0 -g3', cppflags='-fwrapv -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include' ccversion='', gccversion='4.9.2', gccosandvers='' intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3 ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='cc', ldflags =' -fstack-protector-strong -L/usr/local/lib' libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/4.9/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc libc=libc-2.19.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.19' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -O0 -g3 -L/usr/local/lib -fstack-protector-strong' Characteristics of this binary (from libperl): Compile-time options: DEBUGGING HAS_TIMES PERLIO_LAYERS PERL_COPY_ON_WRITE PERL_DONT_CREATE_GVSV PERL_HASH_FUNC_ONE_AT_A_TIME_HARD PERL_MALLOC_WRAP PERL_PRESERVE_IVUV PERL_USE_DEVEL USE_64_BIT_ALL USE_64_BIT_INT USE_LARGE_FILES USE_LOCALE USE_LOCALE_COLLATE USE_LOCALE_CTYPE USE_LOCALE_NUMERIC USE_LOCALE_TIME USE_PERLIO USE_PERL_ATOF Locally applied patches: uncommitted-changes Built under linux Compiled at Jan 21 2016 12:02:54 %ENV: PERLBREW_BASHRC_VERSION="0.43" PERLBREW_HOME="/home/tony/.perlbrew" PERLBREW_PATH="/home/tony/perl5/perlbrew/bin" PERLBREW_ROOT="/home/tony/perl5/perlbrew" @INC: lib /home/tony/perl/blead/lib/site_perl/5.23.8/x86_64-linux /home/tony/perl/blead/lib/site_perl/5.23.8 /home/tony/perl/blead/lib/5.23.8/x86_64-linux /home/tony/perl/blead/lib/5.23.8 .
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 695b
On Wed Jan 20 17:14:21 2016, tonyc wrote: Show quoted text
> This is similar to #127122, but doesn't have quite as simple a fix.
You're right. I started by looking at what you did for #127122, but the "hack" of treating an unless as an if won't work here. Ultimately, I added a few lines of code to op.c to accept this special case - the condition which currently generates the warning, but with an OP_NOT around it. I also added a test for this bug to t/lib/warnings/op, as well as a test for the related while(assignment) case, which didn't have a test. The tests reduce to while(0) and until(1) so as to not hang the entire test suite. All tests pass for me. Patch attached, hopefully formatted correctly.
Subject: 0001-perl-127333-add-warning-for-until-assignment.patch
From 90d93e7911a4471ec779afda1c669a3fe7664d49 Mon Sep 17 00:00:00 2001 From: Dan Collins <dcollinsn@gmail.com> Date: Mon, 6 Jun 2016 21:04:46 -0400 Subject: [PATCH] [perl #127333] add warning for until(assignment) while ($a = 1) emits a warning "Found = in conditional, should be ==". However, until ($a = 1) does not. The parser breaks down until (condition) into while (!(condition)), which defeats the check in S_scalarboolean, since it is looking for a conditional that /is/ an assignment, but we have a conditional that is a thinly veiled assignment. A similar bug was [perl #127122]. That bug was fixed by treating unless (a) {b} else {c} as if (a) {c} else {b}, instead of treating it as if (!a) {b} else {c}. That approach will not work here. Instead, the test in S_scalarboolean has been widened. It previously looked for an OP_SASSIGN with op_first OP_CONST, it now also detects an OP_NOT surrounding that construct. Tests for both while() and until() were also added to t/lib/warnings/op. --- op.c | 7 +++++-- t/lib/warnings/op | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/op.c b/op.c index 619c6e3..9a1f8a4 100644 --- a/op.c +++ b/op.c @@ -1532,8 +1532,11 @@ S_scalarboolean(pTHX_ OP *o) { PERL_ARGS_ASSERT_SCALARBOOLEAN; - if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST - && !(cBINOPo->op_first->op_flags & OPf_SPECIAL)) { + if ((o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST && + !(cBINOPo->op_first->op_flags & OPf_SPECIAL)) || + (o->op_type == OP_NOT && cUNOPo->op_first->op_type == OP_SASSIGN && + cBINOPx(cUNOPo->op_first)->op_first->op_type == OP_CONST && + !(cBINOPx(cUNOPo->op_first)->op_first->op_flags & OPf_SPECIAL))) { if (ckWARN(WARN_SYNTAX)) { const line_t oldline = CopLINE(PL_curcop); diff --git a/t/lib/warnings/op b/t/lib/warnings/op index cf7a798..cc0cf46 100644 --- a/t/lib/warnings/op +++ b/t/lib/warnings/op @@ -134,6 +134,28 @@ Found = in conditional, should be == at - line 3. Found = in conditional, should be == at - line 4. ######## # op.c +# NAME while with assignment as condition +use warnings 'syntax'; +1 while $a = 0; +while ($a = 0) { + 1; +} +EXPECT +Found = in conditional, should be == at - line 3. +Found = in conditional, should be == at - line 4. +######## +# op.c +# NAME until with assignment as condition +use warnings 'syntax'; +1 until $a = 1; +until ($a = 1) { + 1; +} +EXPECT +Found = in conditional, should be == at - line 3. +Found = in conditional, should be == at - line 4. +######## +# op.c use warnings 'syntax' ; @a[3]; @a{3}; -- 2.8.1
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 118b
Tony reports that that didn't apply. Didn't apply for me either. Probably a line endings issue. This one should work.
Subject: 0001-perl-127333-add-warning-for-until-assignment.patch
From 9e26b2c7ce3faf108ded08a9d11d3e37a4515a24 Mon Sep 17 00:00:00 2001 From: Dan Collins <dcollinsn@gmail.com> Date: Mon, 6 Jun 2016 21:04:46 -0400 Subject: [PATCH] [perl #127333] add warning for until(assignment) while ($a = 1) emits a warning "Found = in conditional, should be ==". However, until ($a = 1) does not. The parser breaks down until (condition) into while (!(condition)), which defeats the check in S_scalarboolean, since it is looking for a conditional that /is/ an assignment, but we have a conditional that is a thinly veiled assignment. A similar bug is [perl #127122]. That bug was fixed by treating unless (a) {b} else {c} as if (a) {c} else {b}, instead of treating it as if (!a) {b} else {c}. That approach will not work here. Instead, the test in S_scalarboolean has been widened. It previously looked for an OP_SASSIGN with op_first OP_CONST, it now also detects an OP_NOT surrounding that construct. Tests for both while() and until() were also added to t/lib/warnings/op. --- op.c | 7 +++++-- t/lib/warnings/op | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/op.c b/op.c index 128cdc4..6986610 100644 --- a/op.c +++ b/op.c @@ -1532,8 +1532,11 @@ S_scalarboolean(pTHX_ OP *o) { PERL_ARGS_ASSERT_SCALARBOOLEAN; - if (o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST - && !(cBINOPo->op_first->op_flags & OPf_SPECIAL)) { + if ((o->op_type == OP_SASSIGN && cBINOPo->op_first->op_type == OP_CONST && + !(cBINOPo->op_first->op_flags & OPf_SPECIAL)) || + (o->op_type == OP_NOT && cUNOPo->op_first->op_type == OP_SASSIGN && + cBINOPx(cUNOPo->op_first)->op_first->op_type == OP_CONST && + !(cBINOPx(cUNOPo->op_first)->op_first->op_flags & OPf_SPECIAL))) { if (ckWARN(WARN_SYNTAX)) { const line_t oldline = CopLINE(PL_curcop); diff --git a/t/lib/warnings/op b/t/lib/warnings/op index cf7a798..cc0cf46 100644 --- a/t/lib/warnings/op +++ b/t/lib/warnings/op @@ -134,6 +134,28 @@ Found = in conditional, should be == at - line 3. Found = in conditional, should be == at - line 4. ######## # op.c +# NAME while with assignment as condition +use warnings 'syntax'; +1 while $a = 0; +while ($a = 0) { + 1; +} +EXPECT +Found = in conditional, should be == at - line 3. +Found = in conditional, should be == at - line 4. +######## +# op.c +# NAME until with assignment as condition +use warnings 'syntax'; +1 until $a = 1; +until ($a = 1) { + 1; +} +EXPECT +Found = in conditional, should be == at - line 3. +Found = in conditional, should be == at - line 4. +######## +# op.c use warnings 'syntax' ; @a[3]; @a{3}; -- 2.8.1
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 251b
On Mon Jun 06 19:17:37 2016, dcollinsn@gmail.com wrote: Show quoted text
> Tony reports that that didn't apply. Didn't apply for me either. > Probably a line endings issue. > > This one should work.
Thanks, applied as 0a44e30b028e9918e549705da4512ad5b5a98493. Tony
Download (untitled) / with headers
text/plain 313b
Thank you for filing this report. You have helped make Perl better. With the release today of Perl 5.26.0, this and 210 other issues have been resolved. Perl 5.26.0 may be downloaded via: https://metacpan.org/release/XSAWYERX/perl-5.26.0 If you find that the problem persists, feel free to reopen this ticket.


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org