Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prohibit variable and identifier patterns from being named when or as, to simplify parsing. #3033

Merged
merged 1 commit into from
May 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion accepted/future-releases/0546-patterns/feature-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Author: Bob Nystrom

Status: Accepted

Version 2.31 (see [CHANGELOG](#CHANGELOG) at end)
Version 2.32 (see [CHANGELOG](#CHANGELOG) at end)

Note: This proposal is broken into a couple of separate documents. See also
[records][] and [exhaustiveness][].
Expand Down Expand Up @@ -512,6 +512,10 @@ switch (record) {
}
```

To simplify parsing, the identifier in a variable pattern may not be `when` or
`as`. *This reduces the amount of lookahead needed to correctly parse a guarded
pattern such as `foo when !bar`.*

*There are some restrictions on when `var` and `final` can and can't be used.
They are specified later in the "Pattern context" section.*

Expand Down Expand Up @@ -543,6 +547,13 @@ The answer is it's both. Depending on the context where it appears, a bare
identifier pattern may behave like a constant pattern or like a variable
pattern. The section on pattern context below lays out the precise rules.

For consistency with the corresponding rule for variable patterns, the
identifier in an identifier pattern may not be `when` or `as`. *This is not
strictly necessary for parsing, but it should reduce user confusion by making
identifier patterns consistent with variable patterns. Note however that these
identifiers are allowed as parts of a qualifiedName that forms a
constantPattern, e.g. `when.as`.*

#### Wildcards

As with variable patterns, an identifier pattern named `_` is a wildcard that
Expand Down Expand Up @@ -3510,6 +3521,11 @@ Here is one way it could be broken down into separate pieces:

## Changelog

### 2.32

- Prohibit variable and identifier patterns from being named `when` or `as`,
to simplify parsing.

### 2.31

- Change the technique for resolving the "function expression in guard
Expand Down