linter icon indicating copy to clipboard operation
linter copied to clipboard

discarded_futures lint giving false positives

Open mcmah309 opened this issue 10 months ago • 1 comments

Describe the issue

discarded_futures giving false positives when the future is used as a class argument.

To Reproduce

  Future<int> f(){
    return Future.value(1);
  }

  Arg g(){
    return Arg(f()); // Shows Error here
  }

  Future<void> h() async {
    await g().arg; // but the future is awaited here
  }

class Arg{
  Arg(this.arg);

  Future<int> arg;
}

But this is fine

Future<int> f(){
    return Future.value(1);
  }

  Future<int> g(){
    return f();
  }

  Future<void> h() async {
    await g();
  }

Expected behavior The lint should only happen if the future value is not awaited, returned, or passed as an argument.

mcmah309 avatar Oct 09 '23 12:10 mcmah309