Author: lwall
Date: 2010-02-24 19:26:58 +0100 (Wed, 24 Feb 2010)
New Revision: 29828

Modified:
   docs/Perl6/Spec/S03-operators.pod
Log:
[S03] when and ~~ to warn on direct use of "True" or "False"


Modified: docs/Perl6/Spec/S03-operators.pod
===================================================================
--- docs/Perl6/Spec/S03-operators.pod   2010-02-24 18:11:54 UTC (rev 29827)
+++ docs/Perl6/Spec/S03-operators.pod   2010-02-24 18:26:58 UTC (rev 29828)
@@ -16,7 +16,7 @@
     Created: 8 Mar 2004
 
     Last Modified: 19 Feb 2010
-    Version: 193
+    Version: 194
 
 =head1 Overview
 
@@ -3464,6 +3464,8 @@
     Any       .[...]    array value slice truth ?all(X)  i.e. ?all(.[...])
     Any       .{...}    hash value slice truth  ?all(X)  i.e. ?all(.{...})
     Any       .<...>    hash value slice truth  ?all(X)  i.e. ?all(.<...>)
+    Any       True      ~~ True                 (parsewarn)
+    Any       False     ~~ False match          (parsewarn)
 
     Any       Bool      simple truth            X
     Any       Numeric   numeric equality        +$_ == X
@@ -3680,8 +3682,18 @@
         when .Bool == 0 {...}
     }
 
-Better, just use an C<if> statement.
+Better, just use an C<if> statement.  In any case, if you try to smartmatch
+with C<~~> or C<when>, it will recognize C<True> or C<False> syntactically
+and warn you that it won't do what you expect.  The compiler is also allowed
+to warn about any other boolean construct that does not test C<$_>, to the
+extent it can detect that.
 
+In a similar vein, any function (such as C<grep>) that takes a
+C<Matcher> will not accept an argument of type C<Bool>, since that
+almost always indicates a programming error.  (One may always use
+C<*> to match anything, if that's what you really want.  Or use a closure
+that returns a constant boolean value.)
+
 Note also that regex matching does I<not> return a C<Bool>, but merely
 a C<Match> object that can be used as a boolean value.  Use an explicit
 C<?> or C<true> to force a C<Bool> value if desired.

Reply via email to