You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The compiler complains about switchStatement, reporting that the switch statement doesn't exhaustively cover the cases.
StringswitchStatement() {
switch ([]) {
case [_, ...]:return'at least 1';
case []:return'none';
}
}
StringswitchExpression() =>switch ([]) {
[_, ...] =>'at least 1',
[] =>'none',
};
main.dart:1:8: Error: A non-null value must be returned since the return type 'String' doesn't allow null.
String switchStatement() {
^
This is obviously a fairly contrived case, but I've seen similar patterns come up a few times now. Every problem I've had is solvable, but not always in the nicest of ways.
It seems that the type-checker only does the full exhaustiveness checking for switch expressions or for switch statements with very obvious cases, e.g. if [...] was a case in the above example. I find this to be confusing. Some more discussion here.
What are the thoughts from the language team? Is this possible to support?
The text was updated successfully, but these errors were encountered:
I haven't had a chance to read all of the comments there, but that issue definitely seems to be a match. Sorry for the duplicate, I swear I tried to search the issues first 😅
The compiler complains about
switchStatement
, reporting that the switch statement doesn't exhaustively cover the cases.This is obviously a fairly contrived case, but I've seen similar patterns come up a few times now. Every problem I've had is solvable, but not always in the nicest of ways.
It seems that the type-checker only does the full exhaustiveness checking for switch expressions or for switch statements with very obvious cases, e.g. if
[...]
was a case in the above example. I find this to be confusing. Some more discussion here.What are the thoughts from the language team? Is this possible to support?
The text was updated successfully, but these errors were encountered: