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

discarded_futures not lints inside a function that is inside unawaited #59204

Open
westito opened this issue Jun 28, 2023 · 4 comments
Open

discarded_futures not lints inside a function that is inside unawaited #59204

westito opened this issue Jun 28, 2023 · 4 comments
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-devexp Developer Experience related issues (DevTools, IDEs, Analysis Server, completions, refactoring, etc) linter-false-negative P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@westito
Copy link

westito commented Jun 28, 2023

Describe the issue
When async function wrapped into unawaited, the discarded_futures not lints inside the wrapped function. In this example activate should linted because if not awaited, the try-catch will not catch the exception.

To Reproduce
Képernyőfotó 2023-06-28 - 12 53 16

Expected behavior
activate function is linted in unawaited

@mateusfccp
Copy link
Contributor

IMO this is the expected behavior, as you are explicitly telling that we don't want do wait for the future.

@bwilkerson
Copy link
Member

My interpretation would be that the unawaited means you don't want to await the future returned by guarded (the argument to the function). But I would expect notification related to the future returned by activate because it's in a separate closure, and I don't think the unawaited outside the closure should impact the checking inside the closure.

@westito
Copy link
Author

westito commented Jul 2, 2023

IMO this is the expected behavior, as you are explicitly telling that we don't want do wait for the future.

I don't want to wait for the outer Future, but I want to await the inner Future (it makes sense because if not awaited, the try-catch won't catch the exception)

My interpretation would be that the unawaited means you don't want to await the future returned by guarded (the argument to the function). But I would expect notification related to the future returned by activate because it's in a separate closure, and I don't think the unawaited outside the closure should impact the checking inside the closure.

Yes, that is what i'm saying.

@bwilkerson bwilkerson added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) P3 A lower priority bug or feature request linter-false-negative labels Jul 10, 2023
@lrhn
Copy link
Member

lrhn commented Jul 13, 2023

The discarded_futures lint it's generating a lot of reports, probably because its name doesn't match its meaning.

The description of what the lint does it's to warm if you call an asynchronous function, one which returns a future, in a non async(or async* presumably) function.

There are no exceptions. Using unawaited should not make any difference. It's probably good that it does, but the documentation should say so.
As written, it doesn't matter if or how you use the future.
If you call any function which returns a future, anywhere, the surrounding function must be async! That is it.

I agree that the activate should be a warning in any case.

@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 19, 2024
@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 19, 2024
@bwilkerson bwilkerson added area-devexp Developer Experience related issues (DevTools, IDEs, Analysis Server, completions, refactoring, etc) and removed area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Feb 21, 2025
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-devexp Developer Experience related issues (DevTools, IDEs, Analysis Server, completions, refactoring, etc) linter-false-negative P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants