-
Notifications
You must be signed in to change notification settings - Fork 170
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
[NNBD] explicit_returns #2352
Comments
Just to confirm, I think you're asking for a lint to enforce the style preference of always having an explicit return, even when the returned value is |
Yes, that is correct. |
Please, my team also needs this. It's just now very easy to forget a return, not because you want to return null, but because you forgot to return something different than null in some code branch, and it just assumes it's null and you are on your own, the compiler doesn't care. We've been having a lot of bugs relating to this. |
This issue also comes up in a similar form when implicit control flow jumps via Invoking e.g. a function that returns Never will "automatically throw". void foo() {
bar();
// Anything below bar will never be executed, but there's no throw/return/break/... anywhere which is confusing given how the rest of Dart works
print("baz");
}
Never bar() {...} Forcing users to throw all returned void foo() {
//vvvvv explicit control flow
throw bar();
print("baz");
}
Never bar() {...} So, maybe this issue, and the Never issue mentioned above could be solved by a new |
This is implemented as |
I'm not against this idea; there would be definite benefits to being explicit. If you want to pursue this, please open a new request. |
Thank you @srawlins, that obviously fixes this issue, I failed to consider that. |
Dart interprets not returning anything, as returning a null.
A lint to warn the user to explicitly return null when a null would be inferred due to a missing return statement would be very helpful.
i.e. such that code like:
would emit a warning on the return type that not all code paths have a return statement.
The text was updated successfully, but these errors were encountered: