-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Exhaustive switch case statements consisting of return statements do not satisfy function return requirements #33158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@danbrotherston Unfortunately myFunc(null); |
Gross. Thanks for clarifying. I do find it strange that I don't get a "non-exhaustive" error in that case, and worse, I cannot even make a case statement for This could lead me to write buggy code. I don't normally think of Enums as the type of things that can be |
Agreed. You could always use |
FWIW I am getting the same warning if in this case: enum Foo {A, B}
extension Bar on Foo {
String get value {
switch (this) {
case Foo.A: return "A";
case Foo.B: return "B";
}
}
} In this example I don't think Demonstrated here: https://dartpad.dartlang.org/cf1bf7267acffb795ddbf75fc3b71cbe |
@vrutberg static extension methods are just another syntax for static calls, which means that enum Foo {A, B}
extension Bar on Foo {
String get value {
switch (this) {
case Foo.A: return "A";
case Foo.B: return "B";
default:
print('this=${this}');
}
}
}
void main() {
Foo x = null;
print(x.value);
} |
@mraleph Oh, alright. Thanks for shedding some light on that, that does explain the warning. |
Seeing this using dartpad: https://dartpad.dartlang.org/ (Based on Dart SDK 1.25.0.)
Also seeing in Flutter:
Flutter 0.3.1 • channel beta • https://github.com/flutter/flutter.git
Framework • revision 12bbaba (4 weeks ago) • 2018-04-19 23:36:15 -0700
Engine • revision 09d05a3891
Tools • Dart 2.0.0-dev.48.0.flutter-fe606f890b
I am developing on a Mac.
When I have a switch statement over an Enum, that is exhaustive, if each branch of the switch case has a return statement, I still get an
info
in the compiler indicating the function does not end with a return statement. Inserting a return statement at the end of the function removes this error, despite the fact that I believe this statement cannot execute under any circumstances.This is demonstrated in this 5 line dartpad.
The text was updated successfully, but these errors were encountered: