Skip to content

[patterns] Change if-case statement syntax to a more infix-like form. #2191

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

Merged
merged 1 commit into from
Apr 6, 2022
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
16 changes: 11 additions & 5 deletions working/0546-patterns/patterns-feature-specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Author: Bob Nystrom

Status: In progress

Version 1.5 (see [CHANGELOG](#CHANGELOG) at end)
Version 1.6 (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 @@ -577,13 +577,13 @@ form similar to [if-case in Swift][]:
[if-case in swift]: https://useyourloaf.com/blog/swift-if-case-let/

```dart
if (case [int x, int y] = json) return Point(x, y);
if (json case [int x, int y]) return Point(x, y);
```

It may have an else branch as well:

```dart
if (case [int x, int y] = json) {
if (json case [int x, int y]) {
print('Was coordinate array $x,$y');
} else {
throw FormatException('Invalid JSON.');
Expand All @@ -593,7 +593,7 @@ if (case [int x, int y] = json) {
The grammar is:

```
ifCaseStatement ::= 'if' '(' 'case' matcher '=' expression ')'
ifCaseStatement ::= 'if' '(' expression 'case' matcher ')'
statement ('else' statement)?
```

Expand Down Expand Up @@ -1104,7 +1104,7 @@ is the non-nullable base type of the nullable value being matched:

```dart
String? maybeString = ...
if (case var s? = maybeString) {
if (maybeString case var s?) {
// s has type String here.
}
```
Expand Down Expand Up @@ -1873,6 +1873,12 @@ main() {

## Changelog

### 1.6

- Change syntax of if-case statement ([#2181][]).

[#2181]: https://github.com/dart-lang/language/issues/2181

### 1.5

- Introduce and clarify type inference.
Expand Down