You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
>// This is parsed as: (msg is (not int) or string)
606
+
>result=msgisnotintorstring;
607
+
>Console.WriteLine($"msg (\"msg\"): msg is not int or string: {result}");
608
+
>
604
609
>// This is parsed as: (obj is (int or string)) && flag
605
610
>boolresult=objisintorstring&&flag;
606
611
>Console.WriteLine($"obj (5), flag (true): obj is int or string && flag: {result}");
@@ -622,6 +627,7 @@ When a *pattern* appears on the right-hand-side of `is`, the extent of the patte
622
627
>Theoutputproducedis
623
628
>
624
629
> ```console
630
+
> msg ("msg"):msgisnotintorstring:True
625
631
>obj (5), flag (true):objisintorstring&&flag:True
626
632
>obj (5), flag (true):objisint||objisstring&&flag:True
627
633
>obj (5), flag (false):objisintorstring&&flag:False
@@ -633,9 +639,7 @@ When a *pattern* appears on the right-hand-side of `is`, the extent of the patte
633
639
634
640
## 11.3 Pattern subsumption
635
641
636
-
Inaswitch statement, it is an error if a case’s pattern is *subsumed* by the preceding set of unguarded cases ([§13.8.3](statements.md#1383-the-switch-statement)).
637
-
Informally, this means that any input value would have been matched by one of the previous cases.
638
-
The following rules define when a set of patterns subsumes a given pattern:
642
+
Inaswitch statement, it is an error if a case’s pattern is *subsumed* by the preceding set of unguarded cases ([§13.8.3](statements.md#1383-the-switch-statement)). Informally, this means that any input value would have been matched by one of the previous cases. The following rules define when a set of patterns subsumes a given pattern:
639
643
640
644
A pattern `P` *would match* a constant `K` if any of the following conditions hold:
641
645
@@ -663,8 +667,7 @@ A set of patterns `Q` *subsumes* a pattern `P` if any of the following condition
663
667
664
668
## 11.4 Pattern exhaustiveness
665
669
666
-
Informally, a set of patterns is exhaustive for a type if, for every possible value of that type other than null, some pattern in the set is applicable.
667
-
The following rules define when a set of patterns is *exhaustive* for a type:
670
+
Informally, a set of patterns is exhaustive for a type if, for every possible value of that type other than null, some pattern in the set is applicable. The following rules define when a set of patterns is *exhaustive* for a type:
668
671
669
672
A set of patterns `Q` is *exhaustive* for a type `T` if any of the following conditions hold:
670
673
@@ -678,6 +681,9 @@ A set of patterns `Q` is *exhaustive* for a type `T` if any of the following con
678
681
1. Some pattern in `Q` is a *negated_pattern* `not P₁`, and the patterns in `Q` together with the values not matched by `P₁` cover every possible value of `T`. A *negated_pattern* `not P₁` is exhaustive by itself when `P₁` matches no possible value of `T`; or
679
682
1. Some pattern in `Q` is a *conjunctive_pattern* `P₁ and P₂`, and the set containing only `P₁` is *exhaustive* for `T` and the set containing only `P₂` is *exhaustive* for `T`.
680
683
684
+
> *Note*: When a type pattern includes nullable types, the pattern may be exhaustive for the type but still generate a warning because the type pattern won't match a `null` value. *end note*
685
+
<!-- markdownlint-disable MD028 -->
686
+
681
687
> *Note*: For floating-point types, the combination of patterns `< 0` and `>= 0` is *not* exhaustive because neither relational pattern matches `NaN`. A correct exhaustive set would be `< 0`, `>= 0`, and `double.NaN` (or `float.NaN`). *end note*
682
688
683
689
> *Example*:
@@ -698,3 +704,4 @@ A set of patterns `Q` is *exhaustive* for a type `T` if any of the following con
0 commit comments