develooper Front page | perl.perl5.porters | Postings from January 2011

[perl #81750] Perl 5.12: undef-as-hashref bug

From:
Alexandr Kononoff
Date:
January 7, 2011 01:57
Subject:
[perl #81750] Perl 5.12: undef-as-hashref bug
Message ID:
rt-3.6.HEAD-5425-1294351712-1151.81750-75-0@perl.org
# New Ticket Created by  Alexandr Kononoff 
# Please include the string:  [perl #81750]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=81750 >


# The outpur of the following script is self-explanatory. With perls up to 
v5.10.1 next test script runs perfectly ok without FAILED lines printed. 
With perl v5.12.0 and all newer (including entire 5.13 branch up to 5.13.8, 
as indicated by cpantesters reports) there are FAILED lines in output. The 
pattern of FAILED code is inconsistent, clearly indicating that it is a bug, 
not a feature. Interestingly, this bug affects only constructs in plain 
script code, not that in eval $code. Also, it affects only hashes, not 
similar constructs with arrays (@$foo) or scalars ($$foo). This bug is 
cross-platform (confirmed by cpantesters reports). It is likely to break a 
lot of code out there.

$\ = "\n";
print "Plain script code:";

push @code,     '%$foo';
eval { my $foo;  %$foo;            }; print $@ ? "FAILED: " : "Ok    : ", 
"$code[-1] $@";
push @code,     'scalar %$foo';
eval { my $foo;  scalar %$foo;     }; print $@ ? "FAILED: " : "Ok    : ", 
"$code[-1] $@";
push @code,    '!%$foo;';
eval { my $foo; !%$foo;            }; print $@ ? "FAILED: " : "Ok    : ", 
"$code[-1] $@";

push @code,    'if ( %$foo) {}';
eval { my $foo; if ( %$foo) {}     }; print $@ ? "FAILED: " : "Ok    : ", 
"$code[-1] $@";
push @code,    'if (!%$foo) {}';
eval { my $foo; if (!%$foo) {}     }; print $@ ? "FAILED: " : "Ok    : ", 
"$code[-1] $@";

push @code,    'unless ( %$foo) {}';
eval { my $foo; unless ( %$foo) {} }; print $@ ? "FAILED: " : "Ok    : ", 
"$code[-1] $@";
push @code,    'unless (!%$foo) {}';
eval { my $foo; unless (!%$foo) {} }; print $@ ? "FAILED: " : "Ok    : ", 
"$code[-1] $@";

push @code,    '1 if   %$foo;';
eval { my $foo; 1 if   %$foo;      }; print $@ ? "FAILED: " : "Ok    : ", 
"$code[-1] $@";
push @code,    '1 if ! %$foo;';
eval { my $foo; 1 if ! %$foo;      }; print $@ ? "FAILED: " : "Ok    : ", 
"$code[-1] $@";

push @code,    '1 unless   %$foo;';
eval { my $foo; 1 unless   %$foo;  }; print $@ ? "FAILED: " : "Ok    : ", 
"$code[-1] $@";
push @code,    '1 unless ! %$foo;';
eval { my $foo; 1 unless ! %$foo;  }; print $@ ? "FAILED: " : "Ok    : ", 
"$code[-1] $@";

push @code,    ' %$foo ? 1 : 0;';
eval { my $foo;  %$foo ? 1 : 0;    }; print $@ ? "FAILED: " : "Ok    : ", 
"$code[-1] $@";
push @code,    '!%$foo ? 1 : 0;';
eval { my $foo; !%$foo ? 1 : 0;    }; print $@ ? "FAILED: " : "Ok    : ", 
"$code[-1] $@";


print "\neval \$code:";

eval "{ my \$foo; $_ }" , print $@ ? 'FAILED: ' : 'Ok    : ',  $_
foreach @code;




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About