Inside of a function, the analyzer fails to recognize a callable function when that function is the return value of a provided callback.
When invoking the return value of the callback, the analyzer shows an error with: The expression doesn't evaluate to a function, so it can't be invoked. This only happens when the type of the returned function is typed as a type parameter.
Reduced test case:
void test<F extends Function()>(F Function() getFunction) {
final f = getFunction();
f(); // no error
getFunction()(); // error
(getFunction() as F)(); // error
}
Dart SDK Version:
An expression of type F with bound Function() should be callable (it is "function-type bounded"), so the program should be accepted. The following variant runs with no issues on dart, so it's an issue with the analyzer alone:
void test<F extends Function()>(F Function() getFunction) {
final F f = getFunction();
f();
getFunction()();
(getFunction() as F)();
print("Done");
}
void main() {
test(() => () {});
}
Most helpful comment
An expression of type
Fwith boundFunction()should be callable (it is "function-type bounded"), so the program should be accepted. The following variant runs with no issues ondart, so it's an issue with the analyzer alone: