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
Add FutureOr<T> #28006
Comments
Assigning to @lrhn so he can update the description with more details. |
Does that mean that there will be an explicit class defined in the SDK? |
We are open for suggestions. The type/class is magical, since it's a union type. We can add a Conceptually, |
If we have an explicit declaration, then we don't need to special case navigation (there's someplace with documentation we can take the user), hover text, completions (we don't have to insert a fake class name into the list) and probably a few other features I'm not thinking of immediately. So, it would be much cleaner from server's perspective if there were an actual class, no matter how different the semantics of that class are. Given that it isn't the name of a function, |
Sounds reasonable. I created a bug for it. |
Could we add some tests cases for this so that the implementations can be verified. |
I started writing some tests: |
Informal specification is done: https://gist.github.com/lrhn/d6815f9556acb3dc8f91d2c680ea0e54 Moving to 1.22 for implementation. |
The current language spec has a special type rule when returning a value from an async function. See section "17.12 Return":
Is any of this changing with the introduction of |
No change for the VM's checked mode, for two reasons. One is that it's a requirement on the dynamic type, and there are no objects that has type Also, in spec mode, any occurrence of So all in all, no matter where For strong mode, where [1] It shouldn't be, it should just be Future! We should have a lint for that! |
Marking informal spec and dart2js complete |
Marking VM done. |
Updating checklist to mention that core library usage of this will follow in 1.23. |
Changelog underway: https://codereview.chromium.org/2648203003/ |
Landed! c3f1212 |
Informal specification: https://gist.github.com/lrhn/d6815f9556acb3dc8f91d2c680ea0e54
A lot of asynchronous code in Dart allows the use of a
T
or aFuture<T>
. For example, the callback toFuture.then
is declared to take aT
but it doesn't specify the return type, since it could be anS
or aFuture<S>
:We will add
FutureOr<T>
to support this use case. In strong mode and DDCFutureOr<T>
represents the union ofFuture<T>
andT
. In Dart1,FutureOr<T>
is interpreted asdynamic
.In a following release:
The text was updated successfully, but these errors were encountered: