In perl.git, the branch blead has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/5341b2b7ab11bc31f63ac7a675e74106418d0661?hp=906bad61c3bd0dd3a56a226b2981e4d14d5e71c9>

- Log -----------------------------------------------------------------
commit 5341b2b7ab11bc31f63ac7a675e74106418d0661
Author: Josh ben Jore <[email protected]>
Date:   Wed Sep 23 15:35:14 2009 -0700

    Fix when( scalar ... ) bug
    
    looks_like_bool should look past scalar(). Prior to this fix, saying
    scalar() caused the when() argument to be /not/ a boolean even if it
    reasonably was. Perhaps something like: when( scalar /$re/ ). I don't
    know any natural way someone is doing to use when(scalar ...) but it
    certainly seems like it was mistakenly left out.
-----------------------------------------------------------------------

Summary of changes:
 op.c          |    4 ++++
 t/op/switch.t |   11 ++++++++++-
 2 files changed, 14 insertions(+), 1 deletions(-)

diff --git a/op.c b/op.c
index 729c25f..c3736fa 100644
--- a/op.c
+++ b/op.c
@@ -5194,6 +5194,10 @@ S_looks_like_bool(pTHX_ const OP *o)
                o->op_flags & OPf_KIDS
            && looks_like_bool(cUNOPo->op_first));
 
+        case OP_SCALAR:
+            return looks_like_bool(cUNOPo->op_first);
+
+
        case OP_ENTERSUB:
 
        case OP_NOT:    case OP_XOR:
diff --git a/t/op/switch.t b/t/op/switch.t
index dcec866..80d6b98 100644
--- a/t/op/switch.t
+++ b/t/op/switch.t
@@ -9,7 +9,7 @@ BEGIN {
 use strict;
 use warnings;
 
-plan tests => 127;
+plan tests => 128;
 
 # The behaviour of the feature pragma should be tested by lib/switch.t
 # using the tests in t/lib/switch/*. This file tests the behaviour of
@@ -413,6 +413,15 @@ sub check_outside1 { is($_, "outside", "\$_ lexically 
scoped") }
     is($ok, 'y', "Optimized-away comparison");
 }
 
+{
+    my $ok;
+    given(23) {
+        when (scalar 24) { $ok = 'n'; continue }
+        default { $ok = 'y' }
+    }
+    is($ok,'y','scalar()');
+}
+
 # File tests
 #  (How to be both thorough and portable? Pinch a few ideas
 #  from t/op/filetest.t. We err on the side of portability for

--
Perl5 Master Repository

Reply via email to