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)
647
+
>result=msgisnotintorstring;
648
+
>Console.WriteLine($"msg (\"msg\"): msg is not int or string: {result}");
649
+
>
645
650
>// This is parsed as: (obj is (int or string)) && flag
646
651
>boolresult=objisintorstring&&flag;
647
652
>Console.WriteLine($"obj (5), flag (true): obj is int or string && flag: {result}");
@@ -663,6 +668,7 @@ When a *pattern* appears on the right-hand-side of `is`, the extent of the patte
663
668
>Theoutputproducedis
664
669
>
665
670
> ```console
671
+
> msg ("msg"):msgisnotintorstring:True
666
672
>obj (5), flag (true):objisintorstring&&flag:True
667
673
>obj (5), flag (true):objisint||objisstring&&flag:True
668
674
>obj (5), flag (false):objisintorstring&&flag:False
@@ -675,7 +681,9 @@ When a *pattern* appears on the right-hand-side of `is`, the extent of the patte
675
681
## 11.3 Pattern subsumption
676
682
677
683
Inaswitch statement ([§13.8.3](statements.md#1383-the-switch-statement)), it is an error if a case’s pattern is *subsumed* by the preceding set of *unguarded* ([§13.8.3](statements.md#1383-the-switch-statement)) cases. In a switch expression ([§12.11](expressions.md#1211-switch-expression)), it is an error if a *switch_expression_arm*’s pattern is *subsumed* by the preceding set of *unguarded* *switch_expression_arm*s’ patterns.
684
+
678
685
> *Note*: This means that any input value would have been matched by one of the previous cases or arms. *end note*
686
+
679
687
The following rules define when a set of patterns subsumes a given pattern:
680
688
681
689
A pattern `P` *would match* a constant `K` if any of the following conditions hold:
@@ -721,8 +729,7 @@ A set of patterns `Q` *subsumes* a pattern `P` if any of the following condition
Thefollowingrulesdefine when a set of patterns is *exhaustive* for a type:
732
+
Informally, asetofpatternsisexhaustiveforatypeif, foreverypossiblevalueofthattypeotherthannull, somepatterninthesetisapplicable. Thefollowingrulesdefine when a set of patterns is *exhaustive* for a type:
726
733
727
734
Asetofpatterns `Q` is *exhaustive* foratype `T` ifanyofthefollowingconditionshold:
728
735
@@ -736,6 +743,9 @@ A set of patterns `Q` is *exhaustive* for a type `T` if any of the following con
736
743
1. Somepatternin `Q` isa *negated_pattern* `notP₁`, andthepatternsin `Q` togetherwiththevaluesnotmatchedby `P₁` covereverypossiblevalueof `T`. A*negated_pattern* `notP₁` isexhaustivebyitself when `P₁` matches no possible value of `T`; or
737
744
1. Somepatternin `Q` isa *conjunctive_pattern* `P₁ andP₂`, andthesetcontainingonly `P₁` is*exhaustive* for `T` andthesetcontainingonly `P₂` is *exhaustive* for `T`.
738
745
746
+
> *Note*:Whenatypepatternincludesnullabletypes, thepatternmaybeexhaustiveforthetypebutstillgenerateawarningbecausethetypepatternwon't match a `null` value. *end note*
747
+
<!--markdownlint-disableMD028-->
748
+
739
749
>*Note*:Forfloating-pointtypes, thecombinationofpatterns `<0` and `>=0` is*not*exhaustivebecauseneitherrelationalpatternmatches `NaN`. Acorrectexhaustivesetwouldbe `< 0`, `>=0`, and `double.NaN` (or `float.NaN`). *endnote*
740
750
741
751
>*Example*:
@@ -756,3 +766,4 @@ A set of patterns `Q` is *exhaustive* for a type `T` if any of the following con
0 commit comments