-
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
False positive with await_only_futures #58492
Comments
Thanks for the report. The lint rule looks only at the static type of the expression following In the first two cases the issue isn't the lint rule, it's the fact that the parameter The remaining cases don't have any |
This is (still) a lint issue. In the first two original example, The other cases do indeed not apply, since there is no In general the lint does not recognize that something typed as a type varaible can be a future, but it can if the bound or promotion is a future-like type. The lint currently allows
It should add two more future-like types:
Those two types are also subtypes of import "dart:async";
void main() {}
void foo<T, F extends Future<T>, R extends F, O extends FutureOr<T>>() async {
(await expr<F>()).s<E<T>>;
(await expr<R>()).s<E<T>>;
(await expr<O>()).s<E<T>>;
{
var x = expr<T>();
if (x is Future<int>) {
(await x).s<E<int>>;
}
}
{
var x = expr<T>();
if (x is FutureOr<int>) {
(await x).s<E<int>>;
}
}
}
T expr<T>() => throw "static only test";
typedef E<T> = T Function(T);
extension <T> on T {
void s<X extends E<T>>(){}
} (The example contains code to test the static type after the The lint gives the following warnings, one at each await:
In three of the cases it's just plain wrong that the type is not a subtype of future. The types In the other two cases, the type is a subtype of In each case, awaiting is correct and does something - the type of the result of awaiting differs from the type before awaiting. Omitting the |
Describe the issue
False positive with await_only_futures.
Also, even completely fails to compile valid code in some cases, so may not just be a linter bug.
To Reproduce
f
)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
None.
The text was updated successfully, but these errors were encountered: