Skip to content
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

Analyzer: Future<void> requiring return statement? #31278

Closed
matanlurey opened this issue Nov 3, 2017 · 1 comment
Closed

Analyzer: Future<void> requiring return statement? #31278

matanlurey opened this issue Nov 3, 2017 · 1 comment
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.

Comments

@matanlurey
Copy link
Contributor

matanlurey commented Nov 3, 2017

As of dev-6.0:

Future<void> doThing() async {
  return;
}

... lints the return statement with:

warning: Missing return value after 'return'. (return_without_value at [...])

If I change it to return null;, the warning goes away. Interestingly enough, Future<Null> is fine:

Future<Null> doThing() async {
  return;
}

On a related note - what is the status of Future<void>? I didn't try compiling/running the code.

EDIT: Thanks @munificent - I see that full support is not planned until after the FE migration.

@lrhn
Copy link
Member

lrhn commented Nov 6, 2017

You should probably be allowed to not return, or use return; , with a return type of either void or FutureOr<void> (or FutureOr<FutureOr<void>>, etc).

Maybe something like:

A type is "voidable" if it is void or it is FutureOr<T> and T is voidable. It's an error if a function body contains return; or can reach the end of the body without throwing or returning, unless the function's return type is voidable. It is an error if a function body contains return expr; and the function's return type is void.

The FutureOr<void> type is a little tricky. Any value can be assigned to it, so it's not that different from dynamic, void or Object, and it's not void. There are operations you can do on it - it's just that if it\s not Future<void>, you're not supposed to use it.

@a-siva a-siva added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Nov 9, 2017
@leafpetersen leafpetersen self-assigned this Jun 11, 2018
dart-bot pushed a commit that referenced this issue Jun 15, 2018
various kinds of functions.

Closes-bug: #31887
Closes-bug: #30638
Closes-bug: #32233
Closes-bug: #32881
Closes-bug: #31278
Change-Id: I4ebd7e71096d611e189b571ba5de2998dd11c98b
Reviewed-on: https://dart-review.googlesource.com/60300
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Leaf Petersen <leafp@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion.
Projects
None yet
Development

No branches or pull requests

4 participants