@@ -4,7 +4,7 @@ Author: Bob Nystrom
4
4
5
5
Status: Accepted
6
6
7
- Version 2.31 (see [ CHANGELOG] ( #CHANGELOG ) at end)
7
+ Version 2.32 (see [ CHANGELOG] ( #CHANGELOG ) at end)
8
8
9
9
Note: This proposal is broken into a couple of separate documents. See also
10
10
[ records] [ ] and [ exhaustiveness] [ ] .
@@ -512,6 +512,10 @@ switch (record) {
512
512
}
513
513
```
514
514
515
+ To simplify parsing, the identifier in a variable pattern may not be ` when ` or
516
+ ` as ` . * This reduces the amount of lookahead needed to correctly parse a guarded
517
+ pattern such as ` foo when !bar ` .*
518
+
515
519
* There are some restrictions on when ` var ` and ` final ` can and can't be used.
516
520
They are specified later in the "Pattern context" section.*
517
521
@@ -543,6 +547,13 @@ The answer is it's both. Depending on the context where it appears, a bare
543
547
identifier pattern may behave like a constant pattern or like a variable
544
548
pattern. The section on pattern context below lays out the precise rules.
545
549
550
+ For consistency with the corresponding rule for variable patterns, the
551
+ identifier in an identifier pattern may not be ` when ` or ` as ` . * This is not
552
+ strictly necessary for parsing, but it should reduce user confusion by making
553
+ identifier patterns consistent with variable patterns. Note however that these
554
+ identifiers are allowed as parts of a qualifiedName that forms a
555
+ constantPattern, e.g. ` when.as ` .*
556
+
546
557
#### Wildcards
547
558
548
559
As with variable patterns, an identifier pattern named ` _ ` is a wildcard that
@@ -3524,6 +3535,11 @@ Here is one way it could be broken down into separate pieces:
3524
3535
3525
3536
## Changelog
3526
3537
3538
+ ### 2.32
3539
+
3540
+ - Prohibit variable and identifier patterns from being named `when` or `as`,
3541
+ to simplify parsing.
3542
+
3527
3543
### 2.31
3528
3544
3529
3545
- Change the technique for resolving the "function expression in guard
0 commit comments