Skip to content

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

Closed
@RemcoSchrijver

Description

@RemcoSchrijver

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}');
     }
  },
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagelinter-false-positiveIssues related to lint rules that report a problem when it isn't a problem.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions