Skip to content

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

@eernstg

Description

@eernstg

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NNBDIssues related to NNBD Releaselegacy-area-front-endLegacy: Use area-dart-model instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions