On 23 May 2010 09:04, brian d foy <perlbug-followup@perl.org> wrote:
> I found a case where B::Deparse does the wrong thing. In this foreach-when,
> the 1 == 1 is always true and that block always runs. This is the
> documented behavior, and there is an output line for every input number:
>
> use 5.010;
>
> my $a = 1;
> foreach( 1 .. 10 )
> {
> when( 1 == 1 ) {
> print "Always true. \$_ is $_\n";
> }
> }
>
> This is the result of deparsing on both 5.10.1 through 5.13.1. The 1 == 1 comes
> back as just 1, so now a smart match takes place. Only the first input
> number triggers the when():
>
> sub BEGIN {
> require 5.01;
> }
> BEGIN {
> $^H{'feature_say'} = q(1);
> $^H{'feature_state'} = q(1);
> $^H{'feature_switch'} = q(1);
> }
> my $a = 1;
> foreach $_ (1 .. 10) {
> when (1) {
> print "Always true. \$_ is $_\n";
> }
> }
The easiest way to fix that (and also the correct one, given what
B::Deparse is intended to do) is maybe to always explicitly deparse
the smart match : that is, when ($_~~1) instead of when(1); and for
other cases for non-smartmatch-triggerring syntaxes.
Thread Previous
|
Thread Next