-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
NNBDIssues related to NNBD ReleaseIssues related to NNBD Releaselegacy-area-front-endLegacy: Use area-dart-model instead.Legacy: Use area-dart-model instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)
Description
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
Labels
NNBDIssues related to NNBD ReleaseIssues related to NNBD Releaselegacy-area-front-endLegacy: Use area-dart-model instead.Legacy: Use area-dart-model instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)