-
Notifications
You must be signed in to change notification settings - Fork 1.7k
proposal: extend unawaited_futures
to catch discarded futures when upcast to void
#58656
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
Should we consider any place a
This behaves very differently from I think the rewrite would be to |
Looking at forEach seems like a reasonably starting experiment, but agreed that generalizing feels like something we should strongly consider unless there is good evidence that the generalization has substantially more false positives. |
Thanks for the fix @natebosch. I updated the example. I totally agree that generalizing is preferred and was kind of wanting to babystep but maybe that's too cautious. An experiment where we flag all places where a |
If the feature is generalized a bit, we might as well try to handle the type relationships in a more general manner and see how much it hurts: In a value transfer situation (initialization of variable, assignment to variable or parameter, return), if the expression yielding the value has type We could say something along the following lines: The transition from a type
(We could of course spell this out in terms of specific forms of types, but I tend to think that we should be able to reuse the fundamental structure of "an X-variant position" ;-). We might wish to support a similar notion of "the transition from a type |
The rule for Would this Erik has done the full analysis. I came to basically the same conclusions before reading his. Any place a future is up-cast, it loses future-ness. That happens where a subtype relation depends on a sub-deduction of the form And we should not include If we want to not risk false positives, we might just want to consider upcasts to We originally considered doing "higher order void-preservation", but ended up with just the basic level of "don't use a |
Thanks all for the thoughtful feedback! In our last conversation we discussed an experiment to vet the impact of a constrained generalization which lines up w/ @lrhn's proposal to focus on upcasts to void:
The current plan is to implement that, test internally and externally and then consider broadening to embrace some of @eernstg's further-reaching ideas. |
unawaited_futures
to catch discarded futures in forEach
callsunawaited_futures
to catch discarded futures when upcast to void
See also: #57769 |
extend
unawaited_futures
to catch discarded futures when upcast tovoid
Description
Future results upcast to
void
are not awaited.Details
Future results upcast to
void
are not awaited and are a source of bugs. Commonly, for example, asynchronous callbacks inforEach
don’t get awaited which is surprising.To catch these issues, we propose extending
unawaited_futures
to flag cases whereFuture
s are upcast tovoid
(unless specifically unawaited).Kind
Error
Bad Examples
Good Examples
Desired unawaited futures can be wrapped in an
unawaited
function call:Alternatively, if
await
s are desired, iteration can be re-written like so:Discussion
See also: #58650
Updated 02/23/2022 to broaden the proposal from
forEach
to embrace all upcasts tovoid
.The text was updated successfully, but these errors were encountered: