@@ -1854,24 +1854,17 @@ All other types are not exhaustive. Then:
1854
1854
is to throw an error and most Dart users prefer to catch those kinds of
1855
1855
mistakes at compile time.*
1856
1856
1857
- * If the static type of the matched value in a switch statement is an
1858
- exhaustive type and the cases are not exhaustive then:
1859
-
1860
- * It is a compile-time warning if the type is an enum type or nullable
1861
- enum type. * This is for backwards compatibility.*
1862
-
1863
- * Since enum types are handled specially, why define them as exhaustive?
1864
- This is so that they don't prevent a record type containing them as
1865
- being considered exhaustive. We want it to be a compile-time error if a
1866
- switch on a record type with a sealed type field and an enum type field
1867
- is not exhaustive. We even treat it as an error for switching on a
1868
- record containing only enum types. Since there are no records in the
1869
- wild, this is not a breaking change.*
1870
-
1871
- * Else it is a compile-time error.
1857
+ * It is a compile-time error if the cases in a switch statement are not
1858
+ exhaustive and the static type of the matched value is an exhaustive type.
1872
1859
1873
1860
[ exhaustiveness ] : https://github.com/dart-lang/language/blob/master/working/0546-patterns/exhaustiveness.md
1874
1861
1862
+ ** Breaking change:** Currently, a non-exhaustive switch on an enum type is only
1863
+ a warning. This promotes it to an error. Also, switches on ` bool ` do not have to
1864
+ be exhaustive. In practice, many users already treat warnings as errors, and
1865
+ switches on ` bool ` are rare and unidiomatic. This breaking change would only
1866
+ apply to code that has opted into the language version where this ships.
1867
+
1875
1868
## Runtime semantics
1876
1869
1877
1870
### Execution
@@ -2538,6 +2531,11 @@ Here is one way it could be broken down into separate pieces:
2538
2531
2539
2532
## Changelog
2540
2533
2534
+ ### 2.8
2535
+
2536
+ - Upgrade non-exhaustive switch statements on enums from a warning to an
2537
+ error (#2474 ).
2538
+
2541
2539
### 2.7
2542
2540
2543
2541
- Clarify that relational and extractor patterns can call extension members
0 commit comments