Skip to content

CFE: Accept normal completion in function literal => nullable return type #42743

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 Jul 17, 2020 · 0 comments
Closed
Labels
legacy-area-front-end Legacy: Use area-dart-model instead. NNBD Issues related to NNBD Release type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@eernstg
Copy link
Member

eernstg commented Jul 17, 2020

Cf. #42568, dart-lang/language#1063:

The following program gives rise to a compile-time error in dart (commit bbe8c55), but is accepted by dartanalyzer (same commit):

main() async {
  bool b = true;
  (_) { if (b) return 42; };
}

The program should be accepted, because function literal return type inference treats normal completion of the body is an indication that null may be returned (so it is just as good as return null;).

Consequently, the inferred return type of the above function literal will be int?, and it is then not an error to reach the end of the function body.

@johnniwinther, I'm surprised that I couldn't find an existing issue on this, so forgive me if this is a duplicate.

@eernstg eernstg added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) legacy-area-front-end Legacy: Use area-dart-model instead. NNBD Issues related to NNBD Release labels Jul 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-front-end Legacy: Use area-dart-model instead. NNBD Issues related to NNBD Release type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

1 participant