-
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.
Description
You should be able to pass a function which always throws which can masquerade as having essentially any return type, but currently that is not possible.
Example:
void main() async {
Future<String> Function(int) x = (int v) async {
throw v;
}
}
Gives the following error:
Error: A value of type 'Future<FutureOr<String>> Function(int)' can't be assigned to a variable of type 'Future<String> Function(int)'.
- 'Future' is from 'dart:async'.
- 'FutureOr' is from 'dart:async'.
Future<String> Function(int) x = (int v) async {
It looks like it is inferring the type FutureOr<String>
when it would need to be Future<Never>
or possibly Future<String>
.
If you extract the function literal out to a top level method it is fine:
void main() async {
Future<String> Function(int) y = x;
}
Future<String> x(int v) async {
throw v;
}
This appears to only be a problem in the CFE and not analyzer.
cc @natebosch
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.