Sdk: Analyzer fails to recognize a function as callable

Created on 7 Aug 2020  路  1Comment  路  Source: dart-lang/sdk

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:

  • 2.7.2
  • 2.8.4
  • 2.9.0
area-analyzer type-bug

Most helpful comment

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(() => () {});
}

>All comments

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(() => () {});
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

Hixie picture Hixie  路  3Comments

gspencergoog picture gspencergoog  路  3Comments

55555Mohit55555 picture 55555Mohit55555  路  3Comments

sgrekhov picture sgrekhov  路  3Comments

nex3 picture nex3  路  3Comments