-
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
A value of type 'T & Future<int>' can't be returned from the function 'i' because it has a return type of 'Future<int>'. #47053
Comments
The relevant specification section is this section in the null-safety specification, and the reason why the given situation is an error is that So it is working as specified. But we might want to consider changing |
@leafpetersen, WDYT? |
If |
|
I mean, here's a test case which currently works, and should maybe continue to work: Future<T> k<T>(T x, Future<T> y) async {
if (x is Future<int>) {
return x;
}
return y;
} Although thinking about it a bit more, if |
That one works because there is no promotion (because |
If we just removed the implicit As I read the definition of flatten, flatten( Since Let R be any other type such that Now, it might be that our algorithms won't find that solution because we don't look for it the right way, or forgot to account for type variable intersection types. (Or maybe I'm missing something). |
You're right! -- |
I transferred this issue to the SDK repository because it shows that there is a need to adjust the behavior of the CFE and the analyzer. Here is a summary of the situation: The following example program shows that Future<int> f<T>(T x, Future<int> y) async {
if (x is Future<int>) return x;
return y;
}
void main() => f(0, Future<int>.value(1)); with the following error messages:
The function The future value type of the enclosing function is It looks like |
[Edit by eernstg: This comment contains a brief summary of the situation, and about what we need to change. Subtasks: #47056, #47057]
Originally opened here: #58492
To Reproduce
h
!Since a value of type
T & Future<int>
does have the required typeint | Future<int>
, the error message is inconsistent.Doing
return x as Future<int>;
compiles, but (correctly) warns about an unneccesary cast.i
except forasync
.Expected behavior
No warnings or errors except for the valid warning: "Unnecessary cast.".
Additional context
Using dart 2.13.4.
The text was updated successfully, but these errors were encountered: