Description
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.