-
Notifications
You must be signed in to change notification settings - Fork 1.7k
discarded_futures - incorrectly reporting discarded future #59527
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
If you check the lint description, the rule that it states is:
You're invoking an asynchronous function in a non-async block, so the lint triggers. The lint is not the analogue of |
So the problem is that this lint is generating false positives. The full example would be:
So this is a legitimate use of a future in an sync method and of course being the build method you can't make it async. I don't think this lint should be triggered if the future is being appropriately consumed in a non-ambiguous manner. So :
This is ambiguous as you can't tell if the user intended to return a future - lint should trigger.
This is non-ambiguous - though might be a problem when combined with the lint that tells you to not use types on local variables as tools look vs-code when configured to fix on save will remove the type. My original example using FutureBuiderEx is non-ambiguous so should not trigger. The aim of this lint should be to ensure that user's are not creating a future that will not be consumed rather than just naively complaining if a future is created in a sync method. |
Not according to the lint specification (which is what I consider the documentation to be, since there is nothing else to go by). This is clearly a call to an asynhronous function inside a non- I don't think the specified behavior is a particularly useful, and wouldn't want to enable the lint myself, but the lint is consistently doing what it says it does. (Well, almost, since using
So what you want is a different lint, or a different definition for this lint (aka. a different lint with the same name). I completely agree. The Your possible workarounds are:
|
Closing as WAI. Thanks @lrhn |
I have the class FutureBuilderEx which takes a future as an argument:
FutureBuilderEx takes a future and in the above example
getVersion
returns a future.The problem is that the 'discared_futures' lint reports this as a discarded future when it isn't discarded as it is passed to a method that expects a future.
The above scenario should not trigger the lint.
The text was updated successfully, but these errors were encountered: