Skip to content

Runtime behavior of async return doesn't match static behavior. #22730

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

Closed
lrhn opened this issue Mar 9, 2015 · 3 comments
Closed

Runtime behavior of async return doesn't match static behavior. #22730

lrhn opened this issue Mar 9, 2015 · 3 comments
Labels
area-specification (deprecated) Deprecated: use area-language and a language- label. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@lrhn
Copy link
Member

lrhn commented Mar 9, 2015

The static behavior of "return e;" in an async expression is to check that Future<flatten(T)> (T is static type of e) is assignable to function return type.

The runtime behavior in checked mode is (where S is the runtime type of the value of e):
"If the body of f is marked async (9) it is a dynamic type error if o is
not null (16.2) and Future<S> is not a subtype of the actual return type
(19.8.1) of f."

There is no flatten here, which means that:

import "dart:async";
Future<int> foo() async {
  return new Future.value(42);  // no await.
}
main() {
  foo().then(print);
}

will not give a static warning (flatten(Future<int>) is int), but at runtime it should fail because Future<Future<int>> is not assignable to Future<int>.

I think the flatten should also be applied to the runtime behavior.
Both the Dart VM and dart2js runs the code above with no error and prints 42 in checked mode.

@lrhn lrhn added Type-Defect area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Mar 9, 2015
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed triaged labels Mar 1, 2016
@munificent munificent added area-specification (deprecated) Deprecated: use area-language and a language- label. and removed area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Dec 19, 2016
@eernstg
Copy link
Member

eernstg commented Feb 6, 2018

No milestone now: This does not block Dart 2.

Note that the definition of flatten has been modified since this issue was created, which may imply that the discrepancy does not exist any longer --- this should be checked before closing.

@eernstg
Copy link
Member

eernstg commented Aug 24, 2018

@lrhn, is this done already?

@lrhn
Copy link
Member Author

lrhn commented Aug 27, 2018

I believe the specification is correct and sound on this now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-specification (deprecated) Deprecated: use area-language and a language- label. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants