-
-
Notifications
You must be signed in to change notification settings - Fork 82
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
Need explanation: why missing_return is set to warning #10
Comments
The code works fine. I was very confused when I saw it at first. void main() {
final name = getName();
print(name); // null
}
String getName() {
} Methods in dart automatically return This implicit behaviour will also be String? getName() {
// compiler implicitly injects return null;
} String getName() {
// Error, null isn't allowed
} I don't think anyone wants to rely on the implicit compiler behaviour and a explicit return will make dart easier to read. Therefore I'll change the analyzer:
errors:
missing_return: error |
I read the link, but they have not mentioned the technical reason behind implicit return type. do you know? there is another issue in any reason behind this? |
Every functions in dart has a return value. Even void main() {
// Error: This expression has type 'void' and can't be used.
// print(doSomething());
// Workaround to get the result of a void function
Function f = doSomething;
final result = f();
print(result);
}
void doSomething() {
} From my feeling In the end, all hints/warnings/errors reported by the analyzer are the same thing, colored differently in you IDE. |
Thanks for clarifications. should I create a PR for 'missing_return: error'? |
If I forgot to return value from method complier shows warning instead of error!
why it's a default behavior?
The text was updated successfully, but these errors were encountered: