From: Vincent Pit Date: Fri, 8 Aug 2008 19:08:32 +0000 (+0200) Subject: Fix a bug the handling of if (do { return if ; }) { ... } X-Git-Tag: v0.03~9 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;ds=sidebyside;h=3ad0dc082fd7c56afdc76066a7f8c94c4ae28e69;hp=abeae39be61a1284ff7551d1d669e0b458e264e8;p=perl%2Fmodules%2FSub-Nary.git Fix a bug the handling of if (do { return if ; }) { ... } --- diff --git a/lib/Sub/Nary.pm b/lib/Sub/Nary.pm index 611f780..50ba378 100644 --- a/lib/Sub/Nary.pm +++ b/lib/Sub/Nary.pm @@ -273,7 +273,7 @@ sub inspect { if (null $op) { # If the logop has no else branch, it can also return the *scalar* result of # the conditional - $l3 = { 1 => $c }; + $l3 = { 1 => 1 }; } else { ($r3, $l3) = $self->inspect($op); } diff --git a/samples/cx.pl b/samples/cx.pl index 69bef74..8717d39 100755 --- a/samples/cx.pl +++ b/samples/cx.pl @@ -63,7 +63,7 @@ sub ifr { } my $code = \&wut; -$code = sub { while (do { return 2, 3 }) { } }; + my $bd = B::Deparse->new(); print STDERR $bd->coderef2text($code), "\n"; diff --git a/t/23-branch.t b/t/23-branch.t index 8aced0d..2f97ea8 100644 --- a/t/23-branch.t +++ b/t/23-branch.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 16; +use Test::More tests => 17; use Sub::Nary; @@ -44,7 +44,7 @@ sub ret1234 { } } -sub retinif { +sub retinif1 { if (return 1, 2) { return 1, 2, 3 } else { @@ -52,6 +52,12 @@ sub retinif { } } +sub retinif2 { + if (do { return 2, 3 if $x }) { + return 4, 5, 6; + } +} + my @tests = ( [ \&ret12, { 1 => 0.5, 2 => 0.5 } ], [ \&ret12b, { 1 => 0.5, 2 => 0.5 } ], @@ -73,7 +79,8 @@ my @tests = ( [ \&ret1234, { 2 => 0.5, 3 => 0.25, 4 => 0.125, 1 => 0.125 } ], - [ \&retinif, { 2 => 1 } ], + [ \&retinif1, { 2 => 1 } ], + [ \&retinif2, { 2 => 0.5, 3 => 0.25, 1 => 0.25 } ], ); my $i = 1;