@@ -4,7 +4,7 @@ Author: Bob Nystrom
4
4
5
5
Status: Accepted
6
6
7
- Version 2.22 (see [ CHANGELOG] ( #CHANGELOG ) at end)
7
+ Version 2.23 (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] [ ] .
@@ -2460,10 +2460,39 @@ All other types are not always-exhaustive. Then:
2460
2460
other option is to throw an error and most Dart users prefer to catch those
2461
2461
kinds of mistakes at compile time.*
2462
2462
2463
- * The language doesn't specify or mandate this, but implementations are
2464
- encouraged to report a warning if a case in a switch statement, collection
2465
- element, or expression is unreachable because all values it can match are
2466
- also matched by preceding cases.
2463
+ ** Breaking change:** Currently, a non-exhaustive switch on an enum type is only
2464
+ a warning. This promotes it to an error. Also, switches on ` bool ` do not
2465
+ currently have to be exhaustive. In practice, many users already treat warnings
2466
+ as errors, and switches on ` bool ` are rare and unidiomatic. This breaking change
2467
+ would only apply to code that has opted into the language version where this
2468
+ ships.
2469
+
2470
+ ### Warnings
2471
+
2472
+ We don't want to mandate warnings in the language specification, but the user
2473
+ experience of a language feature is holistic and we try to design it thinking
2474
+ about the entire tooling experience. With that in mind, implementations are
2475
+ encouraged to report a static warning when:
2476
+
2477
+ * The left branch of an ` || ` pattern will always match, since it means the
2478
+ right branch will never be used. A pattern will always match if it's an
2479
+ untyped wildcard, a variable whose type is a supertype of the matched value
2480
+ type, etc.
2481
+
2482
+ * Either branch of an ` && ` is an untyped wildcard, since it has no effect and
2483
+ can be removed.
2484
+
2485
+ * A cast pattern casts to a supertype of the matched value type.
2486
+
2487
+ * A null-check or null-assert pattern has a non-nullable matched value type.
2488
+
2489
+ * A constant pattern's constant has primitive equality and is matched against
2490
+ a type that it can never be equal to, like matching a String against the
2491
+ constant pattern ` 3 ` .
2492
+
2493
+ * A case in a switch statement, collection element, or expression is
2494
+ unreachable because all values it can match are also matched by preceding
2495
+ cases. (The exhaustiveness algorithm can be used to determine this.)
2467
2496
2468
2497
* We make this a warning and not an error because it's harmless dead code.
2469
2498
Also, in some cases the exhaustiveness analysis may not be very precise and
@@ -2472,12 +2501,8 @@ All other types are not always-exhaustive. Then:
2472
2501
that default case may become unreachable. If that happens, we don't want
2473
2502
this to be a breaking change.*
2474
2503
2475
- ** Breaking change:** Currently, a non-exhaustive switch on an enum type is only
2476
- a warning. This promotes it to an error. Also, switches on ` bool ` do not
2477
- currently have to be exhaustive. In practice, many users already treat warnings
2478
- as errors, and switches on ` bool ` are rare and unidiomatic. This breaking change
2479
- would only apply to code that has opted into the language version where this
2480
- ships.
2504
+ In general, these all have the property that they describe dead code that
2505
+ provably can be removed without changing the behavior of the program.
2481
2506
2482
2507
## Runtime semantics
2483
2508
@@ -3436,6 +3461,10 @@ Here is one way it could be broken down into separate pieces:
3436
3461
3437
3462
## Changelog
3438
3463
3464
+ ### 2.23
3465
+
3466
+ - Suggest warnings that implementations may want to report.
3467
+
3439
3468
### 2.22
3440
3469
3441
3470
- In list patterns, don't call `v[e]` if the corresponding subpattern is a
0 commit comments