Closed p5pRT closed 8 years ago
Reply-To: mguttman4@gmail.com Message-Id: \5\.18\.2\_4996\_1451740250@​MEIR\_2 To: perlbug@perl.org Subject: 'unless'\, as opposed to 'if'\, does not issue a warning From: mguttman4@gmail.com
This is a bug report for perl from mguttman4@gmail.com\, generated with the help of perlbug 1.39 running under perl 5.18.2.
# I made a (typical for me) mistake and in the condition of an 'unless' # statement I entered a single '=' rather than a double one '==' for teting # equality. # It silently did its happy but wrong operation. Desperately\, I change it to # "if (same mistake)({next})else{ ... }. Voilà\, a warning. One can see it all # below.
use strict; use warnings; use 5.018;
use Data::Dumper; $Data::Dumper::Sortkeys = 1;
my %original = (aaa=>1\, bbb=> 2\, ccc=> 2\, ddd=> 3\, eee=> 1\, fff=> 0\, ggg=> 1\, hhh=> 2\, jjj=> 0);
########## The correct version ########## my @array; foreach my $key ( sort keys %original ){ my $element = $original{$key}; unless ( $element == 0 ){ push @{$array[$element]}\, $key; } } print Dumper(\@array);
# prints: # $VAR1 = [ # undef\, # ['aaa'\,'eee'\,'ggg']\, # ['bbb'\,'ccc'\,'hhh']\, # ['ddd'] # ];
########## The wrong one but still 'unless' ########## @array = (); foreach my $key ( sort keys %original ){ my $element = $original{$key}; unless ( $element = 0 ){ # ^ # | # ------+ push @{$array[$element]}\, $key; } } print Dumper(\@array);
# Prints: # $VAR1 = [ # ['aaa'\,'bbb'\,'ccc'\,'ddd'\,'eee'\,'fff'\,'ggg'\,'hhh'\,'jjj'] # ]; # ########## The wrong one but using 'if' / 'else' ########## @array = (); foreach my $key ( sort keys %original ){ my $element = $original{$key}; if ( $element = 0 ){ next;} # ^ # | # ------+ else{ push @{$array[$element]}\, $key;} } print Dumper(\@array);
# prints essentially the same but\, ok\, big but\, with a warning! # Shouldn't also the 'unless' version do the same??? # Found = in conditional\, should be == at Unless_does_not_warn.pl line xxx. # $VAR1 = [ # ['aaa'\,'bbb'\,'ccc'\,'ddd'\,'eee'\,'fff'\,'ggg'\,'hhh'\,'jjj'] # ]; #
Flags: category=core severity=low
Site configuration information for perl 5.18.2:
Configured by strawberry-perl at Tue Jan 7 22:34:04 2014.
Summary of my perl5 (revision 5 version 18 subversion 2) configuration:
Platform: osname=MSWin32\, osvers=6.2\, archname=MSWin32-x64-multi-thread uname='Win32 strawberry-perl 5.18.2.1 #1 Tue Jan 7 22:32:35 2014 x64' config_args='undef' hint=recommended\, useposix=true\, d_sigaction=undef useithreads=define\, usemultiplicity=define useperlio=define\, d_sfio=undef\, uselargefiles=define\, usesocks=undef use64bitint=define\, use64bitall=undef\, uselongdouble=undef usemymalloc=n\, bincompat5005=undef Compiler: cc='gcc'\, ccflags =' -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fno-strict-aliasing -mms-bitfields'\, optimize='-s -O2'\, cppflags='-DWIN32' ccversion=''\, gccversion='4.7.3'\, gccosandvers='' intsize=4\, longsize=4\, ptrsize=8\, doublesize=8\, byteorder=12345678 d_longlong=define\, longlongsize=8\, d_longdbl=define\, longdblsize=12 ivtype='long long'\, ivsize=8\, nvtype='double'\, nvsize=8\, Off_t='long long'\, lseeksize=8 alignbytes=8\, prototype=define Linker and Libraries: ld='g++'\, ldflags ='-s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\lib"' libpth=C:\strawberry\c\lib C:\strawberry\c\x86_64-w64-mingw32\lib C:\strawberry\c\lib\gcc\x86_64-w64-mingw32\4.7.3 libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 libc=\, so=dll\, useshrplib=true\, libperl=libperl518.a gnulibc_version='' Dynamic Linking: dlsrc=dl_win32.xs\, dlext=dll\, d_dlsymun=undef\, ccdlflags=' ' cccdlflags=' '\, lddlflags='-mdll -s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\lib"'
Locally applied patches:
@INC for perl 5.18.2: D:\Meir\Dropbox\Shared\Scripts\lib C:/strawberry/perl/site/lib/MSWin32-x64-multi-thread C:/strawberry/perl/site/lib C:/strawberry/perl/vendor/lib C:/strawberry/perl/lib .
Environment for perl 5.18.2: HOME (unset) LANG (unset) LANGUAGE (unset) LC_ALL=en LD_LIBRARY_PATH (unset) LOGDIR (unset)
PATH=C:\ProgramData\Oracle\Java\javapath;C:\strawberry\perl\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Program Files\EmEditor;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\;C:\Program Files\Calibre2\;C:\MinGW\bin;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\Perl64\site\bin;C:\Perl64\bin;C:\Program Files (x86)\Weinmann\Gemeinsame Dateien;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\Doctrine extensions for PHP\;C:\Program Files (x86)\Google\Google Apps Migration\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Git\cmd;C:\Program Files\Perforce;C:\Program Files\Perforce\DVCS\;C:\ProgramData\Oracle\Java\javapath;C:\strawberry\perl\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Program Files\EmEditor;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\;C:\Program Files\Calibre2\;C:\MinGW\bin;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\Perl64\site\bin;C:\Perl64\bin;C:\Program Files (x86)\Weinmann\Gemeinsame Dateien;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\Doctrine extensions for PHP\;C:\Program Files (x86)\Google\Google Apps Migration\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Git\cmd;C:\Program Files\Perforce;C:\Program Files\Perforce\DVCS\;C:\Program Files (x86)\Graphviz2.38\bin;C:\Program Files (x86)\Java\jre7\bin PERL5LIB=D:\Meir\Dropbox\Shared\Scripts\lib PERL_BADLANG (unset) SHELL (unset)
On Sat Jan 02 05:39:05 2016\, mguttman4@gmail.com wrote:
Reply-To: mguttman4@gmail.com Message-Id: \5\.18\.2\_4996\_1451740250@​MEIR\_2 To: perlbug@perl.org Subject: 'unless'\, as opposed to 'if'\, does not issue a warning From: mguttman4@gmail.com
This is a bug report for perl from mguttman4@gmail.com\, generated with the help of perlbug 1.39 running under perl 5.18.2.
# I made a (typical for me) mistake and in the condition of an 'unless' # statement I entered a single '=' rather than a double one '==' for teting # equality. # It silently did its happy but wrong operation. Desperately\, I change it to # "if (same mistake)({next})else{ ... }. Voilà\, a warning. One can see it all # below.
use strict; use warnings; use 5.018;
use Data::Dumper; $Data::Dumper::Sortkeys = 1;
my %original = (aaa=>1\, bbb=> 2\, ccc=> 2\, ddd=> 3\, eee=> 1\, fff=> 0\, ggg=> 1\, hhh=> 2\, jjj=> 0);
########## The correct version ########## my @array; foreach my $key ( sort keys %original ){ my $element = $original{$key}; unless ( $element == 0 ){ push @{$array[$element]}\, $key; } } print Dumper(\@array);
# prints: # $VAR1 = [ # undef\, # ['aaa'\,'eee'\,'ggg']\, # ['bbb'\,'ccc'\,'hhh']\, # ['ddd'] # ];
########## The wrong one but still 'unless' ########## @array = (); foreach my $key ( sort keys %original ){ my $element = $original{$key}; unless ( $element = 0 ){ # ^ # | # ------+ push @{$array[$element]}\, $key; } } print Dumper(\@array);
# Prints: # $VAR1 = [ # ['aaa'\,'bbb'\,'ccc'\,'ddd'\,'eee'\,'fff'\,'ggg'\,'hhh'\,'jjj'] # ]; # ########## The wrong one but using 'if' / 'else' ########## @array = (); foreach my $key ( sort keys %original ){ my $element = $original{$key}; if ( $element = 0 ){ next;} # ^ # | # ------+ else{ push @{$array[$element]}\, $key;} } print Dumper(\@array);
# prints essentially the same but\, ok\, big but\, with a warning! # Shouldn't also the 'unless' version do the same??? # Found = in conditional\, should be == at Unless_does_not_warn.pl line xxx. # $VAR1 = [ # ['aaa'\,'bbb'\,'ccc'\,'ddd'\,'eee'\,'fff'\,'ggg'\,'hhh'\,'jjj'] # ]; #
I confess I'm having difficulty replicating your problem.
Can you simplify the statement by presenting just the code which you feel should throw a warning but fails to do so?
Thank you very much.
--- Flags: category=core severity=low --- Site configuration information for perl 5.18.2:
Configured by strawberry-perl at Tue Jan 7 22:34:04 2014.
Summary of my perl5 (revision 5 version 18 subversion 2) configuration:
Platform: osname=MSWin32\, osvers=6.2\, archname=MSWin32-x64-multi-thread uname='Win32 strawberry-perl 5.18.2.1 #1 Tue Jan 7 22:32:35 2014 x64' config_args='undef' hint=recommended\, useposix=true\, d_sigaction=undef useithreads=define\, usemultiplicity=define useperlio=define\, d_sfio=undef\, uselargefiles=define\, usesocks=undef use64bitint=define\, use64bitall=undef\, uselongdouble=undef usemymalloc=n\, bincompat5005=undef Compiler: cc='gcc'\, ccflags =' -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fno-strict-aliasing -mms-bitfields'\, optimize='-s -O2'\, cppflags='-DWIN32' ccversion=''\, gccversion='4.7.3'\, gccosandvers='' intsize=4\, longsize=4\, ptrsize=8\, doublesize=8\, byteorder=12345678 d_longlong=define\, longlongsize=8\, d_longdbl=define\, longdblsize=12 ivtype='long long'\, ivsize=8\, nvtype='double'\, nvsize=8\, Off_t='long long'\, lseeksize=8 alignbytes=8\, prototype=define Linker and Libraries: ld='g++'\, ldflags ='-s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\lib"' libpth=C:\strawberry\c\lib C:\strawberry\c\x86_64-w64-mingw32\lib C:\strawberry\c\lib\gcc\x86_64-w64-mingw32\4.7.3 libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 libc=\, so=dll\, useshrplib=true\, libperl=libperl518.a gnulibc_version='' Dynamic Linking: dlsrc=dl_win32.xs\, dlext=dll\, d_dlsymun=undef\, ccdlflags=' ' cccdlflags=' '\, lddlflags='-mdll -s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\lib"'
Locally applied patches:
--- @INC for perl 5.18.2: D:\Meir\Dropbox\Shared\Scripts\lib C:/strawberry/perl/site/lib/MSWin32-x64-multi-thread C:/strawberry/perl/site/lib C:/strawberry/perl/vendor/lib C:/strawberry/perl/lib .
--- Environment for perl 5.18.2: HOME (unset) LANG (unset) LANGUAGE (unset) LC_ALL=en LD_LIBRARY_PATH (unset) LOGDIR (unset)
PATH=C:\ProgramData\Oracle\Java\javapath;C:\strawberry\perl\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Program Files\EmEditor;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\;C:\Program Files\Calibre2\;C:\MinGW\bin;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\Perl64\site\bin;C:\Perl64\bin;C:\Program Files (x86)\Weinmann\Gemeinsame Dateien;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\Doctrine extensions for PHP\;C:\Program Files (x86)\Google\Google Apps Migration\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Git\cmd;C:\Program Files\Perforce;C:\Program Files\Perforce\DVCS\;C:\ProgramData\Oracle\Java\javapath;C:\strawberry\perl\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Program Files\EmEditor;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\;C:\Program Files\Calibre2\;C:\MinGW\bin;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\Perl64\site\bin;C:\Perl64\bin;C:\Program Files (x86)\Weinmann\Gemeinsame Dateien;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\Doctrine extensions for PHP\;C:\Program Files (x86)\Google\Google Apps Migration\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Git\cmd;C:\Program Files\Perforce;C:\Program Files\Perforce\DVCS\;C:\Program Files (x86)\Graphviz2.38\bin;C:\Program Files (x86)\Java\jre7\bin PERL5LIB=D:\Meir\Dropbox\Shared\Scripts\lib PERL_BADLANG (unset) SHELL (unset)
-- James E Keenan (jkeenan@cpan.org)
The RT System itself - Status changed from 'new' to 'open'
On Sat Jan 02 18:35:30 2016\, jkeenan wrote:
On Sat Jan 02 05:39:05 2016\, mguttman4@gmail.com wrote:
Reply-To: mguttman4@gmail.com Message-Id: \5\.18\.2\_4996\_1451740250@​MEIR\_2 To: perlbug@perl.org Subject: 'unless'\, as opposed to 'if'\, does not issue a warning From: mguttman4@gmail.com
This is a bug report for perl from mguttman4@gmail.com\, generated with the help of perlbug 1.39 running under perl 5.18.2.
# I made a (typical for me) mistake and in the condition of an 'unless' # statement I entered a single '=' rather than a double one '==' for teting # equality. # It silently did its happy but wrong operation. Desperately\, I change it to # "if (same mistake)({next})else{ ... }. Voilà\, a warning. One can see it all # below.
use strict; use warnings; use 5.018;
use Data::Dumper; $Data::Dumper::Sortkeys = 1;
my %original = (aaa=>1\, bbb=> 2\, ccc=> 2\, ddd=> 3\, eee=> 1\, fff=> 0\, ggg=> 1\, hhh=> 2\, jjj=> 0);
########## The correct version ########## my @array; foreach my $key ( sort keys %original ){ my $element = $original{$key}; unless ( $element == 0 ){ push @{$array[$element]}\, $key; } } print Dumper(\@array);
# prints: # $VAR1 = [ # undef\, # ['aaa'\,'eee'\,'ggg']\, # ['bbb'\,'ccc'\,'hhh']\, # ['ddd'] # ];
########## The wrong one but still 'unless' ########## @array = (); foreach my $key ( sort keys %original ){ my $element = $original{$key}; unless ( $element = 0 ){ # ^ # | # ------+ push @{$array[$element]}\, $key; } } print Dumper(\@array);
# Prints: # $VAR1 = [ # ['aaa'\,'bbb'\,'ccc'\,'ddd'\,'eee'\,'fff'\,'ggg'\,'hhh'\,'jjj'] # ]; # ########## The wrong one but using 'if' / 'else' ########## @array = (); foreach my $key ( sort keys %original ){ my $element = $original{$key}; if ( $element = 0 ){ next;} # ^ # | # ------+ else{ push @{$array[$element]}\, $key;} } print Dumper(\@array);
# prints essentially the same but\, ok\, big but\, with a warning! # Shouldn't also the 'unless' version do the same??? # Found = in conditional\, should be == at Unless_does_not_warn.pl line xxx. # $VAR1 = [ # ['aaa'\,'bbb'\,'ccc'\,'ddd'\,'eee'\,'fff'\,'ggg'\,'hhh'\,'jjj'] # ]; #
I confess I'm having difficulty replicating your problem.
Can you simplify the statement by presenting just the code which you feel should throw a warning but fails to do so?
Thank you very much.
Okay\, I think I have a clearer example:
########## $ cat 127122-assignment-in-unless-fails-to-warn.pl # perl use strict; use warnings; use 5.10.1;
for my $i ( 1..2 ) { if ($i == 2) { say "Yes"; } else { say "No"; } } for my $i ( 1..2 ) { unless ($i == 2) { say "No"; } else { say "Yes"; } } for my $i ( 1..2 ) { if ($i = 2) { say "Yes"; } else { say "No"; } } for my $i ( 1..2 ) { unless ($i = 2) { say "No"; } else { say "Yes"; } } ########## $ perl 127122-assignment-in-unless-fails-to-warn.pl Found = in conditional\, should be == at 127122-assignment-in-unless-fails-to-warn.pl line 16. No Yes No Yes Yes Yes Yes Yes ##########
If I understand you correctly\, you would expect to get *2* "Found = in conditional" warnings: the one shown at line 16 and another at line 20.
Yes\, this seems like a bug to me.
Thank you very much.
--- Flags: category=core severity=low --- Site configuration information for perl 5.18.2:
Configured by strawberry-perl at Tue Jan 7 22:34:04 2014.
Summary of my perl5 (revision 5 version 18 subversion 2) configuration:
Platform: osname=MSWin32\, osvers=6.2\, archname=MSWin32-x64-multi-thread uname='Win32 strawberry-perl 5.18.2.1 #1 Tue Jan 7 22:32:35 2014 x64' config_args='undef' hint=recommended\, useposix=true\, d_sigaction=undef useithreads=define\, usemultiplicity=define useperlio=define\, d_sfio=undef\, uselargefiles=define\, usesocks=undef use64bitint=define\, use64bitall=undef\, uselongdouble=undef usemymalloc=n\, bincompat5005=undef Compiler: cc='gcc'\, ccflags =' -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fno-strict-aliasing -mms-bitfields'\, optimize='-s -O2'\, cppflags='-DWIN32' ccversion=''\, gccversion='4.7.3'\, gccosandvers='' intsize=4\, longsize=4\, ptrsize=8\, doublesize=8\, byteorder=12345678 d_longlong=define\, longlongsize=8\, d_longdbl=define\, longdblsize=12 ivtype='long long'\, ivsize=8\, nvtype='double'\, nvsize=8\, Off_t='long long'\, lseeksize=8 alignbytes=8\, prototype=define Linker and Libraries: ld='g++'\, ldflags ='-s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\lib"' libpth=C:\strawberry\c\lib C:\strawberry\c\x86_64-w64-mingw32\lib C:\strawberry\c\lib\gcc\x86_64-w64-mingw32\4.7.3 libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 libc=\, so=dll\, useshrplib=true\, libperl=libperl518.a gnulibc_version='' Dynamic Linking: dlsrc=dl_win32.xs\, dlext=dll\, d_dlsymun=undef\, ccdlflags=' ' cccdlflags=' '\, lddlflags='-mdll -s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\lib"'
Locally applied patches:
--- @INC for perl 5.18.2: D:\Meir\Dropbox\Shared\Scripts\lib C:/strawberry/perl/site/lib/MSWin32-x64-multi-thread C:/strawberry/perl/site/lib C:/strawberry/perl/vendor/lib C:/strawberry/perl/lib .
--- Environment for perl 5.18.2: HOME (unset) LANG (unset) LANGUAGE (unset) LC_ALL=en LD_LIBRARY_PATH (unset) LOGDIR (unset)
PATH=C:\ProgramData\Oracle\Java\javapath;C:\strawberry\perl\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Program Files\EmEditor;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\;C:\Program Files\Calibre2\;C:\MinGW\bin;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\Perl64\site\bin;C:\Perl64\bin;C:\Program Files (x86)\Weinmann\Gemeinsame Dateien;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\Doctrine extensions for PHP\;C:\Program Files (x86)\Google\Google Apps Migration\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Git\cmd;C:\Program Files\Perforce;C:\Program Files\Perforce\DVCS\;C:\ProgramData\Oracle\Java\javapath;C:\strawberry\perl\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Program Files\EmEditor;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\;C:\Program Files\Calibre2\;C:\MinGW\bin;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\Perl64\site\bin;C:\Perl64\bin;C:\Program Files (x86)\Weinmann\Gemeinsame Dateien;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\Doctrine extensions for PHP\;C:\Program Files (x86)\Google\Google Apps Migration\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Git\cmd;C:\Program Files\Perforce;C:\Program Files\Perforce\DVCS\;C:\Program Files (x86)\Graphviz2.38\bin;C:\Program Files (x86)\Java\jre7\bin PERL5LIB=D:\Meir\Dropbox\Shared\Scripts\lib PERL_BADLANG (unset) SHELL (unset)
-- James E Keenan (jkeenan@cpan.org)
James E Keenan via RT wrote:
Can you simplify the statement by presenting just the code which you feel should throw a warning but fails to do so?
I believe the complaint amounts to this disparity:
$ perl -lwe 'if($a = 2) { }' Found = in conditional\, should be == at -e line 1. $ perl -lwe 'unless($a = 2) { }' $
I expect this occurs due to unless() being rewritten to if(!()). !($a = 2) also doesn't warn.
-zefram
On Sat Jan 02 19:26:32 2016\, zefram@fysh.org wrote:
James E Keenan via RT wrote:
Can you simplify the statement by presenting just the code which you feel should throw a warning but fails to do so?
I believe the complaint amounts to this disparity:
$ perl -lwe 'if($a = 2) { }' Found = in conditional\, should be == at -e line 1. $ perl -lwe 'unless($a = 2) { }' $
I expect this occurs due to unless() being rewritten to if(!()). !($a = 2) also doesn't warn.
Given newCONDOP()'s parameters that seems simple to fix as with the attached.
until ($x = 0) { ... }
has a similar issue\, but the fix won't be quite so simple.
Tony
On Sun Jan 03 15:20:51 2016\, tonyc wrote:
On Sat Jan 02 19:26:32 2016\, zefram@fysh.org wrote:
James E Keenan via RT wrote:
Can you simplify the statement by presenting just the code which you feel should throw a warning but fails to do so?
I believe the complaint amounts to this disparity:
$ perl -lwe 'if($a = 2) { }' Found = in conditional\, should be == at -e line 1. $ perl -lwe 'unless($a = 2) { }' $
I expect this occurs due to unless() being rewritten to if(!()). !($a = 2) also doesn't warn.
Given newCONDOP()'s parameters that seems simple to fix as with the attached.
until ($x = 0) { ... }
has a similar issue\, but the fix won't be quite so simple.
Tony
Correctly handles the test file I attached:
########## $ ./perl -Ilib ~/learn/perl/p5p/127122-assignment-in-unless-fails-to-warn.pl Found = in conditional\, should be == at /home/jkeenan/learn/perl/p5p/127122-assignment-in-unless-fails-to-warn.pl line 16. Found = in conditional\, should be == at /home/jkeenan/learn/perl/p5p/127122-assignment-in-unless-fails-to-warn.pl line 20. No Yes No Yes Yes Yes Yes Yes ##########
I've sent the patch for smoking in the smoke-me/jkeenan/tonyc/127122-unless branch.
-- James E Keenan (jkeenan@cpan.org)
Dear James
Here is a lot simpler one:
use strict; use warnings; use 5.018;
my %original = (aaa=>1\, bbb=> 2\, eee=> 1\, fff=> 0\, jjj=> 0);
say "now with 'unless':";
foreach my $key ( sort keys %original ){ unless ( $original{$key} = 0 ){ say $key; } }
say "now with 'if'-'else':";
foreach my $key ( sort keys %original ){ if ( $original{$key} = 0 ){next;} else{ say $key; } }
#Prints: #Found = in conditional\, should be == at Unless_does_not_warn_2.pl line 19. #now with 'unless': #aaa #bbb #eee #fff #jjj #now with 'if'-'else': #aaa #bbb #eee #fff #jjj
# Please note\, the warning is only about line 19\, NOT line 10!
On Sun\, Jan 3\, 2016 at 4:47 AM\, James E Keenan via RT \< perlbug-followup@perl.org> wrote:
On Sat Jan 02 18:35:30 2016\, jkeenan wrote:
On Sat Jan 02 05:39:05 2016\, mguttman4@gmail.com wrote:
Reply-To: mguttman4@gmail.com Message-Id: \5\.18\.2\_4996\_1451740250@​MEIR\_2 To: perlbug@perl.org Subject: 'unless'\, as opposed to 'if'\, does not issue a warning From: mguttman4@gmail.com
This is a bug report for perl from mguttman4@gmail.com\, generated with the help of perlbug 1.39 running under perl 5.18.2.
# I made a (typical for me) mistake and in the condition of an 'unless' # statement I entered a single '=' rather than a double one '==' for teting # equality. # It silently did its happy but wrong operation. Desperately\, I change it to # "if (same mistake)({next})else{ ... }. Voilà\, a warning. One can see it all # below.
use strict; use warnings; use 5.018;
use Data::Dumper; $Data::Dumper::Sortkeys = 1;
my %original = (aaa=>1\, bbb=> 2\, ccc=> 2\, ddd=> 3\, eee=> 1\, fff=> 0\, ggg=> 1\, hhh=> 2\, jjj=> 0);
########## The correct version ########## my @array; foreach my $key ( sort keys %original ){ my $element = $original{$key}; unless ( $element == 0 ){ push @{$array[$element]}\, $key; } } print Dumper(\@array);
# prints: # $VAR1 = [ # undef\, # ['aaa'\,'eee'\,'ggg']\, # ['bbb'\,'ccc'\,'hhh']\, # ['ddd'] # ];
########## The wrong one but still 'unless' ########## @array = (); foreach my $key ( sort keys %original ){ my $element = $original{$key}; unless ( $element = 0 ){ # ^ # | # ------+ push @{$array[$element]}\, $key; } } print Dumper(\@array);
# Prints: # $VAR1 = [ # ['aaa'\,'bbb'\,'ccc'\,'ddd'\,'eee'\,'fff'\,'ggg'\,'hhh'\,'jjj'] # ]; # ########## The wrong one but using 'if' / 'else' ########## @array = (); foreach my $key ( sort keys %original ){ my $element = $original{$key}; if ( $element = 0 ){ next;} # ^ # | # ------+ else{ push @{$array[$element]}\, $key;} } print Dumper(\@array);
# prints essentially the same but\, ok\, big but\, with a warning! # Shouldn't also the 'unless' version do the same??? # Found = in conditional\, should be == at Unless_does_not_warn.pl line xxx. # $VAR1 = [ # ['aaa'\,'bbb'\,'ccc'\,'ddd'\,'eee'\,'fff'\,'ggg'\,'hhh'\,'jjj'] # ]; #
I confess I'm having difficulty replicating your problem.
Can you simplify the statement by presenting just the code which you feel should throw a warning but fails to do so?
Thank you very much.
Okay\, I think I have a clearer example:
########## $ cat 127122-assignment-in-unless-fails-to-warn.pl # perl use strict; use warnings; use 5.10.1;
for my $i ( 1..2 ) { if ($i == 2) { say "Yes"; } else { say "No"; } } for my $i ( 1..2 ) { unless ($i == 2) { say "No"; } else { say "Yes"; } } for my $i ( 1..2 ) { if ($i = 2) { say "Yes"; } else { say "No"; } } for my $i ( 1..2 ) { unless ($i = 2) { say "No"; } else { say "Yes"; } } ########## $ perl 127122-assignment-in-unless-fails-to-warn.pl Found = in conditional\, should be == at 127122-assignment-in-unless-fails-to-warn.pl line 16. No Yes No Yes Yes Yes Yes Yes ##########
If I understand you correctly\, you would expect to get *2* "Found = in conditional" warnings: the one shown at line 16 and another at line 20.
Yes\, this seems like a bug to me.
Thank you very much.
--- Flags: category=core severity=low --- Site configuration information for perl 5.18.2:
Configured by strawberry-perl at Tue Jan 7 22:34:04 2014.
Summary of my perl5 (revision 5 version 18 subversion 2) configuration:
Platform: osname=MSWin32\, osvers=6.2\, archname=MSWin32-x64-multi-thread uname='Win32 strawberry-perl 5.18.2.1 #1 Tue Jan 7 22:32:35 2014 x64' config_args='undef' hint=recommended\, useposix=true\, d_sigaction=undef useithreads=define\, usemultiplicity=define useperlio=define\, d_sfio=undef\, uselargefiles=define\, usesocks=undef use64bitint=define\, use64bitall=undef\, uselongdouble=undef usemymalloc=n\, bincompat5005=undef Compiler: cc='gcc'\, ccflags =' -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DUSE_PERLIO -fno-strict-aliasing -mms-bitfields'\, optimize='-s -O2'\, cppflags='-DWIN32' ccversion=''\, gccversion='4.7.3'\, gccosandvers='' intsize=4\, longsize=4\, ptrsize=8\, doublesize=8\, byteorder=12345678 d_longlong=define\, longlongsize=8\, d_longdbl=define\, longdblsize=12 ivtype='long long'\, ivsize=8\, nvtype='double'\, nvsize=8\, Off_t='long long'\, lseeksize=8 alignbytes=8\, prototype=define Linker and Libraries: ld='g++'\, ldflags ='-s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\lib"' libpth=C:\strawberry\c\lib C:\strawberry\c\x86_64-w64-mingw32\lib C:\strawberry\c\lib\gcc\x86_64-w64-mingw32\4.7.3 libs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 perllibs=-lmoldname -lkernel32 -luser32 -lgdi32 -lwinspool -lcomdlg32 -ladvapi32 -lshell32 -lole32 -loleaut32 -lnetapi32 -luuid -lws2_32 -lmpr -lwinmm -lversion -lodbc32 -lodbccp32 -lcomctl32 libc=\, so=dll\, useshrplib=true\, libperl=libperl518.a gnulibc_version='' Dynamic Linking: dlsrc=dl_win32.xs\, dlext=dll\, d_dlsymun=undef\, ccdlflags=' ' cccdlflags=' '\, lddlflags='-mdll -s -L"C:\strawberry\perl\lib\CORE" -L"C:\strawberry\c\lib"'
Locally applied patches:
--- @INC for perl 5.18.2: D:\Meir\Dropbox\Shared\Scripts\lib C:/strawberry/perl/site/lib/MSWin32-x64-multi-thread C:/strawberry/perl/site/lib C:/strawberry/perl/vendor/lib C:/strawberry/perl/lib .
--- Environment for perl 5.18.2: HOME (unset) LANG (unset) LANGUAGE (unset) LC_ALL=en LD_LIBRARY_PATH (unset) LOGDIR (unset)
PATH=C:\ProgramData\Oracle\Java\javapath;C:\strawberry\perl\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS
Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Program Files\EmEditor;C:\Program Files\Microsoft SQL
Server\110\Tools\Binn\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\;C:\Program
Files\Calibre2\;C:\MinGW\bin;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\Perl64\site\bin;C:\Perl64\bin;C:\Program Files (x86)\Weinmann\Gemeinsame Dateien;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\Doctrine extensions for PHP\;C:\Program Files (x86)\Google\Google Apps Migration\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Git\cmd;C:\Program Files\Perforce;C:\Program
Files\Perforce\DVCS\;C:\ProgramData\Oracle\Java\javapath;C:\strawberry\perl\bin;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS
Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\Program Files\EmEditor;C:\Program Files\Microsoft SQL
Server\110\Tools\Binn\;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\;C:\Program
Files\Calibre2\;C:\MinGW\bin;C:\strawberry\c\bin;C:\strawberry\perl\site\bin;C:\Perl64\site\bin;C:\Perl64\bin;C:\Program Files (x86)\Weinmann\Gemeinsame Dateien;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\;C:\Program Files (x86)\MySQL\MySQL Fabric 1.5.3 & MySQL Utilities 1.5.3 1.5\Doctrine extensions for PHP\;C:\Program Files (x86)\Google\Google Apps Migration\;C:\Program Files (x86)\Skype\Phone\;C:\Program Files\Git\cmd;C:\Program Files\Perforce;C:\Program Files\Perforce\DVCS\;C:\Program Files (x86)\Graphviz2.38\bin;C:\Program Files (x86)\Java\jre7\bin PERL5LIB=D:\Meir\Dropbox\Shared\Scripts\lib PERL_BADLANG (unset) SHELL (unset)
-- James E Keenan (jkeenan@cpan.org)
-- -- Me
On Sun Jan 03 15:20:51 2016\, tonyc wrote:
On Sat Jan 02 19:26:32 2016\, zefram@fysh.org wrote:
James E Keenan via RT wrote:
Can you simplify the statement by presenting just the code which you feel should throw a warning but fails to do so?
I believe the complaint amounts to this disparity:
$ perl -lwe 'if($a = 2) { }' Found = in conditional\, should be == at -e line 1. $ perl -lwe 'unless($a = 2) { }' $
I expect this occurs due to unless() being rewritten to if(!()). !($a = 2) also doesn't warn.
Given newCONDOP()'s parameters that seems simple to fix as with the attached.
Applied as 08b3e84fbb1c493d7157c2ad8d1dec4242c965cc.
until ($x = 0) { ... }
has a similar issue\, but the fix won't be quite so simple.
Created ticket 127933 for this.
Tony
@tonycoz - Status changed from 'open' to 'pending release'
Thank you for submitting this report. You have helped make Perl better.
With the release of Perl 5.24.0 on May 9\, 2016\, this and 149 other issues have been resolved.
Perl 5.24.0 may be downloaded via https://metacpan.org/release/RJBS/perl-5.24.0
@khwilliamson - Status changed from 'pending release' to 'resolved'
Migrated from rt.perl.org#127122 (status was 'resolved')
Searchable as RT127122$