-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Choose the type argument for the future returned from an invocation of an async function #33213
Comments
@lrhn, @leafpetersen do you agree that we should extend the specification to make an explicit choice in this area? I suppose it will fit as an update of dartLangSpec.tex directly, with no intervening feature specification. |
Yes, we should specify this. I think the right answer is that the returned value should be a |
Right, that would be as follows (
The first three may seem slightly accidental, but they also seem "natural" (and, of course, as a run-time type they would all be |
I've created a CL updating dartLangSpec.tex to say this (including, of course, similar rules for The specification doesn't actually prevent an implementation from returning an object whose clausal supertype at Future<String> returnsString() async {
return null;
} it would be acceptable for an invocation of |
Addressing #33213. Change-Id: I383d496c46fa0d1bf9313f315ad767eb21577eb6 Reviewed-on: https://dart-review.googlesource.com/56487 Reviewed-by: Lasse R.H. Nielsen <lrn@google.com> Reviewed-by: Leaf Petersen <leafp@google.com>
Addressing dart-lang/sdk#33213. Change-Id: I383d496c46fa0d1bf9313f315ad767eb21577eb6 Reviewed-on: https://dart-review.googlesource.com/56487 Reviewed-by: Lasse R.H. Nielsen <lrn@google.com> Reviewed-by: Leaf Petersen <leafp@google.com>
When an async function is invoked, a fresh instance of
Future<T>
for someT
is returned at some point, and there is no user-written code which creates that future so the choice ofT
is not made by a developer. The specification currently leaves it unspecified which value to use forT
:This issue serves to recommend that we specify this type argument explicitly.
To get started we may consider a couple of loose ideas:
Future<T> f() async {...}
should return an instance ofFuture<T>
.void f() async {...}
should return an instance ofFuture<void>
.FutureOr<T> f() async {...}
should probably return an instance ofFuture<T>
. Etc.The text was updated successfully, but these errors were encountered: