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)
607
+
>result=msgisnotintorstring;
608
+
>Console.WriteLine($"msg (\"msg\"): msg is not int or string: {result}");
609
+
>
605
610
>// This is parsed as: (obj is (int or string)) && flag
606
611
>boolresult=objisintorstring&&flag;
607
612
>Console.WriteLine($"obj (5), flag (true): obj is int or string && flag: {result}");
@@ -623,6 +628,7 @@ When a *pattern* appears on the right-hand-side of `is`, the extent of the patte
623
628
>Theoutputproducedis
624
629
>
625
630
> ```console
631
+
> msg ("msg"):msgisnotintorstring:True
626
632
>obj (5), flag (true):objisintorstring&&flag:True
627
633
>obj (5), flag (true):objisint||objisstring&&flag:True
628
634
>obj (5), flag (false):objisintorstring&&flag:False
@@ -634,9 +640,7 @@ When a *pattern* appears on the right-hand-side of `is`, the extent of the patte
634
640
635
641
## 11.3 Pattern subsumption
636
642
637
-
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)).
638
-
Informally, this means that any input value would have been matched by one of the previous cases.
639
-
The following rules define when a set of patterns subsumes a given pattern:
643
+
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:
640
644
641
645
A pattern `P` *would match* a constant `K` if any of the following conditions hold:
642
646
@@ -664,8 +668,7 @@ A set of patterns `Q` *subsumes* a pattern `P` if any of the following condition
664
668
665
669
## 11.4 Pattern exhaustiveness
666
670
667
-
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.
668
-
The following rules define when a set of patterns is *exhaustive* for a type:
671
+
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:
669
672
670
673
A set of patterns `Q` is *exhaustive* for a type `T` if any of the following conditions hold:
671
674
@@ -679,6 +682,9 @@ A set of patterns `Q` is *exhaustive* for a type `T` if any of the following con
679
682
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
680
683
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`.
681
684
685
+
> *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*
686
+
<!-- markdownlint-disable MD028 -->
687
+
682
688
> *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*
683
689
684
690
> *Example*:
@@ -699,3 +705,4 @@ A set of patterns `Q` is *exhaustive* for a type `T` if any of the following con
0 commit comments