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
Copy file name to clipboardExpand all lines: standard/patterns.md
+32-3Lines changed: 32 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ A pattern is tested against a value in a number of contexts:
11
11
- In a switch expression, the *pattern* of a *switch_expression_arm* is tested against the expression on the switch-expression’s left-hand-side.
12
12
- In nested contexts, the *sub-pattern* is tested against values retrieved from properties, fields, or indexed from other input values, depending on the pattern form.
13
13
14
-
The value against which a pattern is tested is called the ***pattern input value***. Patterns may be combined using Boolean logic.
14
+
The value against which a pattern is tested is called the ***pattern input value***.
15
15
16
16
## 11.2 Pattern forms
17
17
@@ -34,6 +34,8 @@ pattern
34
34
;
35
35
```
36
36
37
+
The `'(' pattern ')'` production allows a pattern to be enclosed in parentheses to enforce the order of evaluation among patterns combined using one of the *logical_pattern*s.
38
+
37
39
Some *pattern*s can result in the declaration of a local variable.
38
40
39
41
Each pattern form defines the set of types for input values that the pattern may be applied to. A pattern `P` is *applicable to* a type `T` if `T` is among the types whose values the pattern may match. It is a compile-time error if a pattern `P` appears in a program to match a pattern input value ([§11.1](patterns.md#111-general)) of type `T` if `P` is not applicable to `T`.
@@ -438,7 +440,7 @@ relational_pattern
438
440
439
441
Relational patterns support the relational operators `<`, `<=`, `>`, and `>=` on all of the built-in types that support such binary relational operators with both operands having the same type: `sbyte`, `byte`, `short`, `ushort`, `int`, `uint`, `long`, `ulong`, `char`, `float`, `double`, `decimal`, `nint`, `nuint`, and enums.
440
442
441
-
It is a compile-time error if `constant_expression`is`double.NaN`, `float.NaN`, or `null_literal`.
443
+
It is a compile-time error if `constant_expression` evaluates to one of`double.NaN`, `float.NaN`, or `null_literal`.
442
444
443
445
When the input value has a type for which a suitable built-in binary relational operator is defined, the evaluation of that operator is taken as the meaning of the relational pattern. Otherwise, the input value is converted to the type of `constant_expression` using an explicit nullable or unboxing conversion. It is a compile-time error if no such conversion exists. The pattern is considered to not match if the conversion fails. If the conversion succeeds, the result of the pattern-matching operation is the result of evaluating the expression `e «op» v` where `e` is the converted input, «op» is the relational operator, and `v` is the `constant_expression`.
444
446
@@ -471,7 +473,7 @@ When the input value has a type for which a suitable built-in binary relational
471
473
472
474
### §logical-pattern-new-clause Logical pattern
473
475
474
-
A *logical_pattern* isusedtonegateapatterninputvalue ([§11.1](patterns.md#111-general)) ortocombinethatvaluewithapatternusingaBooleanoperator.
476
+
A *logical_pattern* isusedtonegatetheresultofmatchingapatterninputvalue ([§11.1](patterns.md#111-general)) ortocombinethatmatchresultwithapatternusingaBooleanoperator.
475
477
476
478
```ANTLR
477
479
logical_pattern
@@ -561,6 +563,33 @@ When a *pattern* is used with `is`, any pattern operators in that *pattern* have
0 commit comments