Skip to content
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

unawaited_futures should consider try {return future} as unawaited #59489

Closed
rrousselGit opened this issue Jul 31, 2024 · 3 comments
Closed

unawaited_futures should consider try {return future} as unawaited #59489

rrousselGit opened this issue Jul 31, 2024 · 3 comments
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-false-negative P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug

Comments

@rrousselGit
Copy link

Describe the issue
When returning a Future inside async functions, when wrapped in a try block, that future won't trigger an unawaited lint

To Reproduce

Future<void> fn() async {
  try {
    return Future.value();
  } catch (e) {
    ...
  }
}

Expected behavior

The return future line should emit an unawaited_futures. And awaiting it or marking it as unawaited should make the issue disappear.

Additional context

This is a common mistake. The catch/finally blocks may not trigger correctly when the returned future is unawaited.

@lrhn
Copy link
Member

lrhn commented Aug 1, 2024

It's a bug that return future; does not await the future (#44395).
As such, the linter is technically correct, it's the implementation that is wrong.

Haven't been able to make it impossible to return a future yet (dart-lang/language#870), which would force you to write the await.

@srawlins
Copy link
Member

srawlins commented Aug 1, 2024

I think we can consider this a duplicate of #58279, or vice versa if we want to update unawaited_futures.

@srawlins srawlins added type-enhancement A request for a change that isn't a bug P3 A lower priority bug or feature request linter-false-negative labels Aug 1, 2024
@srawlins
Copy link
Member

Duplicate of #58234

@devoncarew devoncarew added analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Nov 20, 2024
@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-false-negative P3 A lower priority bug or feature request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants