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

A return statement should not be required in an async method #22091

Closed
kevmoo opened this issue Jan 16, 2015 · 14 comments
Closed

A return statement should not be required in an async method #22091

kevmoo opened this issue Jan 16, 2015 · 14 comments
Assignees
Labels
analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P1 A high priority bug; for example, a single project is unusable or has many test failures
Milestone

Comments

@kevmoo
Copy link
Member

kevmoo commented Jan 16, 2015

Future fuze() async {
  await new Future.value();
}

Expected:

no hint/error. This is a valid async method.

Actual:
Hint: This function declares a return type of 'Future', but does not end with a return statement

@DartBot
Copy link

DartBot commented Jan 19, 2015

This comment was originally written by @seaneagan


As with issue #22092, it would have been nice to be able to do:

void fuze() async {
  await new Future.value();
}

@DartBot
Copy link

DartBot commented Jan 19, 2015

This comment was originally written by @mezoni


As in Ruby???

def name
  my_name
end

How this can be related to current Dart syntax?

===========
The return statement returns a result to the caller of a synchronous function,
completes the future associated with an asynchronous function or terminates the
stream or iterable associated with a generator (9).
===========

You propose remove the following rule?

===========
Otherwise the return statement is executed by executing the statement
return null;
===========

As with issue #22092, it would have been nice to be able to do:

void fuze() async {
  await new Future.value();
}

Believe me it is not good.

@bwilkerson
Copy link
Member

Added Priority-High label.

@DartBot
Copy link

DartBot commented Jan 21, 2015

This comment was originally written by @Emasoft


An async method should NEVER have void as return type! Async void is EVIL. It is a 'fire and forget' insanely dangerous thing. It is the worst language design feature since "goto" (and incidentally for very similar reasons!). It's a well known language design error known to cause only bugs, all almost impossible to track. We suffered enough pain for it in C#, where the very designer of the language admitted the error. Please don't do the same error in Dart. We discussed the problem before here: https://code.google.com/p/dart/issues/detail?id=104

@DartBot
Copy link

DartBot commented Jan 21, 2015

This comment was originally written by @seaneagan


I'm not sure why "async void" in C# is "fire and forget", but using a "void" return type for "async" methods in dart would be nothing like that.

This:

void foo async {
  await new Future.value();
}

would be the same as:

Futre<Null> foo async {
  await new Future.value();
}

except that it would validate (as much as is possible in a dynamically typed language) that the completion value of the future is not used.

Since using async is just supposed to be an implementation detail though, it would need to be possible to write methods which return Future&lt;void> without using async, which is issue #2231.

@DartBot
Copy link

DartBot commented Jan 22, 2015

This comment was originally written by @Emasoft


@seaneagan1 wrote:

I'm not sure why "async void" in C# is "fire and forget"

Have you read the linked issue #104? Or this article?
http://www.jayway.com/2012/10/07/asyncawait-in-c-a-disaster-waiting-to-happen/

@DartBot
Copy link

DartBot commented Jan 22, 2015

This comment was originally written by @seaneagan


Yes, I agree that is something that an "extract method" refactoring should handle when code containing an await is extracted from an async method.

But it's unrelated to the proposal here for Future&lt;void>, which would signify that the completion value of the future cannot be used, not that the returned Future cannot be awaited as is apparently the case with C#.

@stereotype441
Copy link
Member

Set owner to @stereotype441.
Added Started label.

@stereotype441
Copy link
Member

Fixed in revision 43361.


Added Fixed label.

@kevmoo
Copy link
Member Author

kevmoo commented Feb 5, 2015

Dart VM version: 1.9.0-dev.6.0

Thanks!


Added Verified label.

@kevmoo
Copy link
Member Author

kevmoo commented Feb 9, 2015

This seems to have regressed

Dart VM version: 1.9.0-dev.7.1


Attachment:
[Screen Shot 2015-02-09 at 9.50.48 AM.png](https://storage.googleapis.com/google-code-attachments/dart/issue-22091/comment-12/Screen Shot 2015-02-09 at 9.50.48 AM.png) (37.15 KB)


Added Triaged label.

@stereotype441
Copy link
Member

I'm investigating.

@kevmoo
Copy link
Member Author

kevmoo commented Feb 9, 2015

False alarm: this is still fixed, but not pack-ported to the Java analyzer


Added Fixed label.

@kevmoo kevmoo added Type-Defect P1 A high priority bug; for example, a single project is unusable or has many test failures area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-warning Issues with the analyzer's Warning codes labels Feb 9, 2015
@kevmoo kevmoo added this to the 1.9 milestone Feb 9, 2015
@levrik
Copy link

levrik commented Mar 7, 2018

@kevmoo Still getting this error displayed in Android Studio with the latest Dart plugin and Dart 2. Compiles fine though.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P1 A high priority bug; for example, a single project is unusable or has many test failures
Projects
None yet
Development

No branches or pull requests

5 participants