@@ -607,7 +607,7 @@ is expected.
607
607
### List pattern
608
608
609
609
```
610
- listPattern ::= typeArguments? '[' patterns ']'
610
+ listPattern ::= typeArguments? '[' patterns? ']'
611
611
```
612
612
613
613
A list pattern matches an object that implements ` List ` and extracts elements by
@@ -622,7 +622,7 @@ elements. Allow capturing the rest in a variable.**
622
622
### Map pattern
623
623
624
624
```
625
- mapPattern ::= typeArguments? '{' mapPatternEntries '}'
625
+ mapPattern ::= typeArguments? '{' mapPatternEntries? '}'
626
626
mapPatternEntries ::= mapPatternEntry ( ',' mapPatternEntry )* ','?
627
627
mapPatternEntry ::= expression ':' pattern
628
628
```
@@ -648,7 +648,7 @@ It is a compile-time error if:
648
648
### Record pattern
649
649
650
650
```
651
- recordPattern ::= '(' patternFields ')'
651
+ recordPattern ::= '(' patternFields? ')'
652
652
patternFields ::= patternField ( ',' patternField )* ','?
653
653
patternField ::= ( identifier? ':' )? pattern
654
654
```
@@ -690,6 +690,11 @@ Field subpatterns can be in one of three forms:
690
690
(:field as int)
691
691
```
692
692
693
+ A record pattern with a single unnamed field and no trailing comma is ambiguous
694
+ with a grouping pattern. In that case, it is treated as a grouping pattern. To
695
+ write a record pattern that matches a single unnamed field, add a trailing
696
+ comma, as you would with the corresponding record expression.
697
+
693
698
### Extractor pattern
694
699
695
700
```
@@ -1687,6 +1692,14 @@ behavior.
1687
1692
3 . If no case pattern matched and there is a default clause, execute the
1688
1693
statements after it.
1689
1694
1695
+ 4 . If no case matches and there is no default clause, throw a runtime
1696
+ exception. * This can only occur when ` null ` or a legacy typed value flows
1697
+ into this switch statement from another library that hasn't migrated to
1698
+ [ null safety] [ ] . In fully migrated programs, exhaustiveness checking is
1699
+ sound and it isn't possible to reach this runtime error.*
1700
+
1701
+ [ null safety ] : https://dart.dev/null-safety
1702
+
1690
1703
#### Switch expression
1691
1704
1692
1705
1 . Evaluate the switch value producing ` v ` .
@@ -1707,6 +1720,12 @@ behavior.
1707
1720
expression after it and yield that as the result of the entire switch
1708
1721
expression.
1709
1722
1723
+ 4 . If no case matches and there is no default clause, throw a runtime
1724
+ exception. * This can only occur when ` null ` or a legacy typed value flows
1725
+ into this switch expression from another library that hasn't migrated to
1726
+ [ null safety] [ ] . In fully migrated programs, exhaustiveness checking is
1727
+ sound and it isn't possible to reach this runtime error.*
1728
+
1710
1729
#### Pattern-if statement
1711
1730
1712
1731
1 . Evaluate the ` expression ` producing ` v ` .
@@ -1958,6 +1977,15 @@ Here is one way it could be broken down into separate pieces:
1958
1977
1959
1978
## Changelog
1960
1979
1980
+ ### 2.3
1981
+
1982
+ - Specify that switches throw a runtime error if values from legacy libraries
1983
+ flow in and break exhaustiveness checking (#2123 ).
1984
+
1985
+ - Allow empty list, map, and record patterns (#2441 ).
1986
+
1987
+ - Clarify ambiguity between grouping and record patterns.
1988
+
1961
1989
### 2.2
1962
1990
1963
1991
- Make map patterns check length like list patterns do (#2415 ).
0 commit comments