-
Notifications
You must be signed in to change notification settings - Fork 213
Specification: Incorrect type check rule for async
return.
#929
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
Comments
5 cents, if you allow: it would be better to deny using |
Hello @ili! There's nothing that prevents writing an Future<int> foo() async => 1; So what would it mean to deny using [Edit] I think I know what you mean now: When an await is needed in order to perform a In this particular case the main issue is that the specification needs to be fixed for correctness. It does connect to #914 as well, because it prepares the spec for not causing a breaking change by accident when we change the assignability rules along with the introduction of null-safety. |
I'm not sure about must - there's nothing wrong with the rule. I'm happy to consider changing it though. Is this just a sub-issue for your revisit of the return rules? |
I don't understand why you do not think that the following is a bug in the specification:
Future<Future<int>> g() async {
return Future<int>.value(42);
}
As I see it, it is obviously a spec bug when it is a compile-time error to return an expression of type |
The rules in the language specification about return statements in an
async
function include the following:The context for this rule is that we are considering
return e;
where the static type ofe
is$S$
(written asS
when already in math mode), in anasync
function$f$
with declared return type$T$
. A typical example would be the following:This is allowed, because
$S$
as well as\code{Future<\flatten{S}>}
isFuture<int>
, and$T$
isFuture<num>
. Similarly,return 42
is allowed because\code{Future<\flatten{S}>}
is againFuture<int>
.However, the following should be allowed, but is currently specified to be a compile-time error:
Here,
\code{Future<\flatten{S}>}
isFuture<int>
and$T$
isFuture<Future<int>>
, and the former is not assignable to the latter.So we must change this rule.
Note that the vm and dart2js already run the following code with no issues:
The analyzer currently rejects this program, but it is a non-breaking change to allow it. Also, the analyzer reports the following:
which is wrong with respect to the type of the returned expression as well as the declared return type, so there would be a need to take a look at the relevant code for this check in any case.
The text was updated successfully, but these errors were encountered: