Skip to content

Can mixed_return_types be relaxed for async functions that return Future<void>? #58060

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

Closed
jamesderlin opened this issue Nov 21, 2019 · 2 comments
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead.

Comments

@jamesderlin
Copy link
Contributor

Given the following code:

Future<void> _cachedFuture;

Future<void> foo(String arg) async {
  if (arg.isEmpty) {
    return;
  }

  if (_cachedFuture != null) {
    return _cachedFuture;
  }

  _cachedFuture = Future.delayed(const Duration(seconds: 1));
  await _cachedFuture;
  print('Done');
}

Future<void> main() async {
  await foo('');
  await foo('xyzzy');
}

dartanalyzer will complain about the return; line:

error • Functions can't include return statements both with and without values. • return_future.dart:7:5 • mixed_return_types
error • Functions can't include return statements both with and without values. • return_future.dart:11:5 • mixed_return_types
2 errors found.

This seems overzealous for an async function declared to return Future<void> given that:

Future<void> f() async {
  return;
}

Future<void> g() async {
  return f();
}

are legal and since the analyzer doesn't complain about not having a return statement when reaching the end of the function.

To avoid the analysis error, I need to replace return; with return Future.value(), which I think is less clear.

@eernstg
Copy link
Member

eernstg commented Nov 21, 2019

There is no rule that returns cannot be mixed like this, but we used to have such a rule. Cf. #39476.

@eernstg
Copy link
Member

eernstg commented Nov 21, 2019

I believe there is no connection to the linter in this issue, and the SDK issue has been reported, so I'll close this issue.

@eernstg eernstg closed this as completed Nov 21, 2019
@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 18, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead.
Projects
None yet
Development

No branches or pull requests

3 participants