Open
Description
Running the code:
void main() {
void Function(int) f = (() => 42) as void Function(int);
}
generates an error:
type '() => int' is not a subtype of type '(int) => void' in type cast
I think it would be better if the error message used Dart's normal syntax for Function
types. That is, I think the error message would be better as:
type 'int Function()' is not a subtype of type 'void Function(int)` in type cast.
Note that the analyzer already does that. If I remove the cast, the analyzer reports:
A value of type 'void Function()' can't be
assigned to a variable of type 'void Function(int)'. Try changing
the type of the variable, or casting the right-hand type to 'void
Function(int)'. • invalid_assignment
(The example above is contrived (people should not be performing explicit casts on Function
objects in practice), but that form of error is encountered in the wild (often with a combination of generic classes, callbacks, and accidentally omitted type parameters).)