Skip to content

Analyzer: Mixed returns is not an error any more #39476

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
eernstg opened this issue Nov 21, 2019 · 2 comments
Closed

Analyzer: Mixed returns is not an error any more #39476

eernstg opened this issue Nov 21, 2019 · 2 comments
Assignees
Labels
legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@eernstg
Copy link
Member

eernstg commented Nov 21, 2019

Consider the following library:

import 'dart:async';

Future<void> foo(bool b) async {
  if (b) return;
  return null;
}

As of 54011e5, dartanalyzer reports errors for this library:

ERROR|STATIC_WARNING|MIXED_RETURN_TYPES|/usr/local/google/home/eernst/lang/dart/scratch/201911/n045.dart|4|10|6|Functions can't include return statements both with and without values.
ERROR|STATIC_WARNING|MIXED_RETURN_TYPES|/usr/local/google/home/eernst/lang/dart/scratch/201911/n045.dart|5|3|6|Functions can't include return statements both with and without values.

The language specification used to have a rule saying that it is a compile-time error to have both return; and return e; in the same function, but this is no longer the case. The change occurred in SDK commit 9388cb3, and it was a consequence of integrating the feature specification invalid-returns.md into the specification. So the analyzer should stop checking and reporting mixed_return_types. The current spec text is here.

@eernstg eernstg added legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Nov 21, 2019
@bwilkerson bwilkerson self-assigned this Nov 21, 2019
@bwilkerson
Copy link
Member

Fixed by https://dart-review.googlesource.com/c/sdk/+/125927.

@eernstg The test co19_2/Language/Statements/Return/many_return_statements_t01 appears to be based on the old spec. Could you please double check and follow up with the co19 team if necessary?

@eernstg
Copy link
Member Author

eernstg commented Nov 25, 2019

I created an issue in the co19 repo for that, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants