Skip to content

useResult odd behavior with awaited Future's #60162

@Guru-Zachw

Description

@Guru-Zachw

@useResult is used to ensure that the result returned from a function is used. But it's current implementation is 'mustSetToVariable'. Usually those are 1-1, however there is a case where that is not true. In the case of a function that returns a Future, the Future can be used, without it being set to a variable.
EX:
dart```
import 'package:meta/meta.dart';

@useResult
Future testFuture() async {
await Future.delayed(Duration(seconds: 1));
return 1;
}

void main() async {
await testFuture();
}


In this example, the testFuture's return value has been 'used'. We have waited for the returned future to complete. A copy of the functionality like so
dart```
void main() async {
  final future = testFuture();
  await future;
}

no longer shows the warning, but the outcome is the same.

I am attempting to argue to not show the warning if the result of a function is a Future and that Future is awaited.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-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-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions