-
Notifications
You must be signed in to change notification settings - Fork 1.7k
discarded_futures
lint discussion
#59887
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
Just to keep things in one place. The current CL fixes all of the above issues. I'll read through https://gist.github.com/lrhn/0316c1c6c5102dc900d635d08ec31188 and see if there is any missing test here. I'll also address to the linter/analyzer team the following question: With the current changes, if the |
One more issue that is a duplicate from the list above #59949. |
To note:
I'd appreciate some inputs here @pq. |
My quick 2 cents:
My gut says if this route is considered valuable we could explore updating
I'm not sure either. I'd be curious, in practice, if this happens a lot. The downside to a blanket special-case is that we may miss flagging unintended behavior. I wonder if a more principled approach might be something along the lines of function-side opt outs as discussed for |
I also just ran into this not working as I expected... in particular in my case it interacts poorly with dart code metrics "avoid-redundant-async" lint, which will trigger if I add an I ended up having to ignore the lint on that line as I could not find any way to make both things happy. |
In that case, since I'm still unsure about any assignment at all because that could make users assign that to |
Imo, if you use the future in any way, regardless of the type it is being assigned to, the lint should not trigger. |
Basically the same as @pq, any takes on why this wasn't done from the start? Not sure if you remember it but maybe there was some reason? |
@FMorschel: sorry, I can't recall. Possibly just an incomplete thought. |
I've refactored the CL for the lint itself. Could someone please take a look? Thanks a lot! This CL is simply to review the current two fixes for |
Three more things to consider here:
|
If you invoke a member on a If you invoke an extension member on a If you're passing the future as an argument to a parameter which is typed as (Not sure how to handle parameters with a generic type that is instantiated to be Wrapping a An interpolation like Awaiting is like an operand with a parameter type of (We may want to handle variables specially, allowing you to do non-future things to a variable tired as a if (cachedFuture != newFuture) {
newFuture.ignore();
cachedFuture = cachedFuture.then((_) => newFuture);
} Here the call to Basically, we want to make sure that a |
Ah ok, so it would be standard to write
I only bring it up because I know of some (I believe popular) subclasses: package:async's DelegatingFuture (and ResultFuture?), Flutter's AsynchronousFuture, TickerFuture, some internal classes (DisposableFuture, CancelableFuture, ZonedFuture, InterruptableFuture, and more), gRPC's ResponseFuture, firebase_storage's Task. It just seems like the |
If a class implements If a class extends the interface of But if it implements |
[email protected] Bug: #59887 Fixes: #59504 Fixes: #58889 Fixes: #59455 Fixes: #59151 Fixes: #59387 Fixes: #59331 Fixes: #59949 Change-Id: I6d93a36f626650b744e2e4ec52bbefe171483820 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403901 Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Auto-Submit: Felipe Morschel <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
Bug: #59887 Change-Id: I04fe23275435249be3533649d1c276c7afe8ee4e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416240 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Phil Quitslund <[email protected]> Auto-Submit: Felipe Morschel <[email protected]> Reviewed-by: Phil Quitslund <[email protected]>
Do we have any other lints today that share part of their code? In any way similar to what we want here, I mean. Bots broke after the landing of the two CLs at the same time so I opened https://dart-review.googlesource.com/c/sdk/+/417900 |
I haven't read this thread recently, but I'm guessing that you're asking about the question of whether a class is a "Future"-enough class, in which case the answer is "yes". We have lints that use the same concept and therefore share an implementation of that concept. For example, the recently added lints around "obvious" type annotations all share a common implementation of what it means for a type annotation to be "obvious". |
Thanks! I'll take a look. I'll see if I can make both After that, we can implement the above discussion about another meaning of "using" the |
Bug: #59887 Change-Id: I6c8204771b70d49091f882e5b7f875b158724b89 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417900 Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Phil Quitslund <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Auto-Submit: Felipe Morschel <[email protected]>
After some discussion over at #59877, #59331 and #58747, I've seen many users expecting
discarded_futures
to work similarly tounawaited_futures
but inside synchronous code.That is, inside synchronous code, if the
Future
is assigned to something that explicitly asks for aFuture
, do nothing, if not, trigger.That would solve all of these duplicates that expect the lint not to warn when using it on
FutureBuilder
from Flutter for example:discarded_futures
lint #58889discarded_futures
: Unwaited return for when Future is expected #59331Making the behaviour match
unawaited_futures
would also probably fix: #59204.I've opened https://dart-review.googlesource.com/c/sdk/+/403901 and I've made some changes to address this assignability issue, but @lrhn commented on the CL:
I'm opening this issue to track this discussion and hopefully to make that change.
// CC @lrhn @pq
The text was updated successfully, but these errors were encountered: