Skip to content

Commit 52fe6d2

Browse files
committed
add warning on smartmatch of Match or Nil
1 parent 7551b8f commit 52fe6d2

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

STD.pm6

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3801,15 +3801,17 @@ grammar P6 is STD {
38013801

38023802
token dumbsmart {
38033803
[ \h*
3804-
('True'|'False'|'Bool::True'|'Bool::False') <?before \s>
3804+
('True'|'False'|'Bool::True'|'Bool::False'|'Match'|'Nil')
38053805
{
38063806
my $litbool = $0[0].Str;
3807-
my $true = $litbool ~~ /True/;
3807+
my $true = $litbool ~~ /True|Match/;
3808+
my $suggest =
3809+
$true ?? ':so or *.so or ?*' !!
3810+
$litbool ~~ /Nil/ ?? '* === Nil or :!defined' !!
3811+
':!so or *.not or !*';
38083812
self.worry("Smartmatch against $litbool always " ~
38093813
($true ?? 'matches' !! 'fails') ~
3810-
"; if you mean to test the topic for\n truthiness, please use " ~
3811-
($true ?? ':so or *.so or ?*' !! ':!so or *.not or !*') ~
3812-
' instead');
3814+
"; perhaps you should use $suggest instead");
38133815
}
38143816
]?
38153817
}

0 commit comments

Comments
 (0)