Runtime behavior of async return doesn't match static behavior. #22730
Labels
area-specification (deprecated)
Deprecated: use area-language and a language- label.
type-bug
Incorrect behavior (everything from a crash to more subtle misbehavior)
Uh oh!
There was an error while loading. Please reload this page.
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:
will not give a static warning (
flatten(Future<int>)
isint
), but at runtime it should fail becauseFuture<Future<int>>
is not assignable toFuture<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.
The text was updated successfully, but these errors were encountered: