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

[analyzer] False positives for discarded_futures when passing future-returning function call as an argument #59151

Open
RemcoSchrijver opened this issue May 21, 2023 · 1 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-positive P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@RemcoSchrijver
Copy link

Issue encountered while using austerity package, when passing a future function as parameter it wrongfully marks it as an discared_future issue, an example using flutter is provided below. For background on the issue already raised with austerity see this issue.

Looking at the priorities file this should be marked as a p2 issue, as mentioned in the other thread this is fixed by ignoring the rule for this line. I also did not find any other issues on this fact.

An example of code generating a false positive would be:
Future<String> getValue() async {
  await Future.delayed(Duration(seconds: 3));
  return 'Woolha';
}

FutureBuilder<String>(
  future: getValue(),
  builder: (
    BuildContext context,
    AsyncSnapshot<String> snapshot,
    ) {
      print(snapshot.connectionState);
      if (snapshot.connectionState == ConnectionState.waiting) {
        return CircularProgressIndicator();
      } else if (snapshot.connectionState == ConnectionState.done) {
      if (snapshot.hasError) {
         return const Text('Error');
       } else if (snapshot.hasData) {
         return Text(snapshot.data);
       } else {
         return const Text('Empty data');
       }
     } else {
       return Text('State: ${snapshot.connectionState}');
     }
  },
)
@lrhn lrhn transferred this issue from dart-lang/sdk May 21, 2023
@MelbourneDeveloper
Copy link
Contributor

@RemcoSchrijver, this has been an issue for me as well. There are situations when you need to return a future in a non-async scenario, and this is one. It means that we have to ignore the linter in a lot of places.

@pq pq added linter-false-positive P3 A lower priority bug or feature request labels Jun 13, 2023
@srawlins srawlins added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Apr 3, 2024
@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
@srawlins srawlins changed the title [analyzer] False positives for discarded_futures when passing future function as parameter [analyzer] False positives for discarded_futures when passing future-returning function call as an argument Jan 8, 2025
@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-positive 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

6 participants