Skip to content

Commit

Permalink
Standardize list pattern lowering on Index constructor. (#5484)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekseyTs authored Dec 4, 2021
1 parent b1ada74 commit df75a20
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions proposals/list-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,19 +78,19 @@ The behavior of a pattern-matching operation is undefined if any of the above as

#### Lowering

A pattern of the form `expr is [1, 2, 3]` is equivalent to the following code (if compatible via implicit `Index` support):
A pattern of the form `expr is [1, 2, 3]` is equivalent to the following code:
```cs
expr.Length is 3
&& expr[0] is 1
&& expr[1] is 2
&& expr[2] is 3
&& expr[new Index(0, fromEnd: false)] is 1
&& expr[new Index(1, fromEnd: false)] is 2
&& expr[new Index(2, fromEnd: false)] is 3
```
A *slice_pattern* acts like a proper discard i.e. no tests will be emitted for such pattern, rather it only affects other nodes, namely the length and indexer. For instance, a pattern of the form `expr is [1, .. var s, 3]` is equivalent to the following code (if compatible via explicit `Index` and `Range` support):
```cs
expr.Length is >= 2
&& expr[new Index(0)] is 1
&& expr[new Range(1, new Index(1, true))] is var s
&& expr[new Index(1, true)] is 3
&& expr[new Index(0, fromEnd: false)] is 1
&& expr[new Range(new Index(1, fromEnd: false), new Index(1, fromEnd: true))] is var s
&& expr[new Index(1, fromEnd: true)] is 3
```
The *input type* for the *slice_pattern* is the return type of the underlying `this[Range]` or `Slice` method with two exceptions: For `string` and arrays, `string.Substring` and `RuntimeHelpers.GetSubArray` will be used, respectively.

Expand Down

0 comments on commit df75a20

Please sign in to comment.