Skip to content

discarded_futures : Unwaited return for when Future is expected #59331

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

Closed
bsz0206 opened this issue Oct 20, 2023 · 8 comments
Closed

discarded_futures : Unwaited return for when Future is expected #59331

bsz0206 opened this issue Oct 20, 2023 · 8 comments
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-linter Issues with the analyzer's support for the linter package P2 A bug or feature request we're likely to work on type-question A question about expected behavior or functionality

Comments

@bsz0206
Copy link

bsz0206 commented Oct 20, 2023

Unwaited does work only on void returns. We are forced to ignore, which is not nice:

FutureBuilder(
// ignore: discarded_futures
future: asyncCall(),

Unwaited does work only on void returns:
FutureBuilder(
future: unawaited(asyncCall()),,

@devoncarew
Copy link
Member

Thanks for the report; this repo is for proposals to add existing lints to our recommended lint set. You might want to re-file this at the dart-lang/sdk repo?

@bsz0206
Copy link
Author

bsz0206 commented Oct 20, 2023

thanks. can you refer me to the page?

@pq pq transferred this issue from dart-archive/lints Oct 20, 2023
@pq pq reopened this Oct 20, 2023
@pq pq changed the title Unwaited return for when Future is expected discarded_futures : Unwaited return for when Future is expected Oct 20, 2023
@pq pq added the type-question A question about expected behavior or functionality label Oct 20, 2023
@lrhn
Copy link
Member

lrhn commented Oct 21, 2023

The discarded_futures lint is causing a lot of confusion. It's name doesn't match it's description, and it's unclear which the implementation is matching, if either.

The description doesn't say that using unawaitedshould have any effect.
To turn off the lint, you should change the surrounding function to being async.

See #59204.

@pq pq added the P2 A bug or feature request we're likely to work on label Oct 30, 2023
@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 20, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 20, 2024
@FMorschel
Copy link
Contributor

Hey @bsz0206, considering #59204, I've tested

import 'dart:async';

Future<void> f() async {}

void g() {
  unawaited(f());
}

And got no lint, so I think this can be closed?


If you have any other problems with the FutureBuilder widget, you may want to have a look at (which are all duplicates):

@bsz0206
Copy link
Author

bsz0206 commented Jan 9, 2025

No, the use case is different. The future functions returns something other than void:

Future getMeAnString() async {
/* ... */
}

FutureBuilder(
future: getMeAnString(),
builder: ..
...
)

then I would get: Asynchronous function invoked in a non-'async' function. Try converting the enclosing function to be 'async' and then 'await' the future. and I will have to add an //ignore :

FutureBuilder(
// ignore: discarded_futures
future: getMeAnString(),
builder: ..
...
)

This literally means almost every FutureBuilder would need an extra ignore that is not nice.

Hey @bsz0206, considering #59204, I've tested

import 'dart:async';

Future<void> f() async {}

void g() {
  unawaited(f());
}

And got no lint, so I think this can be closed?

@FMorschel
Copy link
Contributor

Thanks for clarifying! Then this is the same as the other issues I mentioned. I'm working on a fix for this.

@FMorschel
Copy link
Contributor

@pq here is the CL: https://dart-review.googlesource.com/c/sdk/+/403901

Once you review it, can you also take a look at all of the issues mentioned to make sure you agree they are dupes? Thanks!

@FMorschel
Copy link
Contributor

I noticed that this should consider FutureOr. I'll review it later today. Also, I'll open another issue to address that it shows the unnawaited fix for FutureOr but that is not valid.

@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed legacy-area-analyzer Use area-devexp instead. labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-linter Issues with the analyzer's support for the linter package P2 A bug or feature request we're likely to work on type-question A question about expected behavior or functionality
Projects
Archived in project
Development

No branches or pull requests

6 participants