@@ -4,15 +4,17 @@ Author: Bob Nystrom
4
4
5
5
Status: In progress
6
6
7
- Version 1.3 (see [ CHANGELOG] ( #CHANGELOG ) at end)
7
+ Version 1.4 (see [ CHANGELOG] ( #CHANGELOG ) at end)
8
8
9
- ## Summary
9
+ Note: This proposal is broken into a couple of separate documents. See also
10
+ [ records] [ ] and [ exhaustiveness] [ ] .
11
+
12
+ [ records ] : https://github.com/dart-lang/language/blob/master/working/0546-patterns/records-feature-specification.md
10
13
11
- This proposal (along with its smaller sister [ records proposal] [ ] ) covers a
12
- family of closely-related features that address a number of some of the most
13
- highly-voted user requests. It directly addresses:
14
+ ## Summary
14
15
15
- [ records proposal ] : https://github.com/dart-lang/language/blob/master/working/0546-patterns/records-feature-specification.md
16
+ This proposal covers a family of closely-related features that address a number
17
+ of some of the most highly-voted user requests. It directly addresses:
16
18
17
19
* [ Multiple return values] ( https://github.com/dart-lang/language/issues/68 ) (495 👍, 4th highest)
18
20
* [ Algebraic datatypes] ( https://github.com/dart-lang/language/issues/349 ) (362 👍, 10th highest)
@@ -1549,52 +1551,11 @@ is a key part of maintaining code written in an algebraic datatype style. It's
1549
1551
the functional equivalent of the error reported when a concrete class fails to
1550
1552
implement an abstract method.
1551
1553
1552
- Exhaustiveness checking is * critical* for switch * expressions:*
1553
-
1554
- ``` dart
1555
- int i = switch ("str") {
1556
- case "a" => 1;
1557
- case "oops" => 2;
1558
- };
1559
- ```
1560
-
1561
- An expression must reliably evaluate to * some* value, unlike statements where
1562
- you can simply do nothing if no case matches. We could throw a runtime error if
1563
- no case matches, but that's generally not useful for users.
1564
-
1565
- Exhaustiveness checking is more complex in the presence of pattern matching and
1566
- destructuring:
1567
-
1568
- ``` dart
1569
- bool xor(bool a, bool b) =>
1570
- switch ((a, b)) {
1571
- case (true, true) => false;
1572
- case (true, false) => true;
1573
- case (false, true) => true;
1574
- case (false, false) => false;
1575
- };
1576
- ```
1577
-
1578
- This is exhaustive, but it's not obvious how this would be determined. A
1579
- related problem is unreachable patterns:
1554
+ Exhaustiveness checking over arbitrarily deeply nested record and extractor
1555
+ patterns can be complex, so the proposal for that is in a [ separate
1556
+ document] [ exhaustiveness ] .
1580
1557
1581
- ``` dart
1582
- switch (obj) {
1583
- case num n: print("number");
1584
- case int i: print("integer");
1585
- }
1586
- ```
1587
-
1588
- Here, the second case will never match because any value that could match it
1589
- will be caught by the first case. It's not necessary to detect unreachable
1590
- patterns for correctness, but it helps users if we can since the case is dead
1591
- code.
1592
-
1593
- A trivial way to ensure all switches are exhaustive is to require a default
1594
- case or case containing only a wildcard pattern (with no guard).
1595
-
1596
- ** TODO: See if we can detect exhaustive and unreachable cases more precisely.
1597
- See: http://moscova.inria.fr/~maranget/papers/warn/index.html **
1558
+ [ exhaustiveness ] : https://github.com/dart-lang/language/blob/master/working/0546-patterns/exhaustiveness.md
1598
1559
1599
1560
## Runtime semantics
1600
1561
@@ -1826,6 +1787,10 @@ main() {
1826
1787
1827
1788
## Changelog
1828
1789
1790
+ ### 1.4
1791
+
1792
+ - Link to [ exhaustiveness] [ ] proposal.
1793
+
1829
1794
### 1.3
1830
1795
1831
1796
- Avoid unbounded lookahead with switch expression in an expression statement
0 commit comments