Skip to content

False positive of avoid_dynamic_calls on .call() #58309

@askeksa-google

Description

@askeksa-google

The avoid_dynamic_calls lint was recently implemented by @matanlurey in dart-archive/linter#2417. Whenever the program contains a .call() or ?.call() call on a receiver of function type, the lint will always flag the call, even if the receiver is not dynamic.

The cases are illustrated by this code:

class A {
  void call() {}
}

typedef F = void Function();

void fun() {}

void test(A a, A? an, F f, F? fn, dynamic d, Function df, Function? dfn) {
  a(); // OK
  f(); // OK
  d(); // LINT
  df(); // LINT

  a.call(); // OK
  an?.call(); // OK
  f.call(); // OK !
  fn?.call(); // OK !
  d.call(); // LINT
  df.call(); // LINT
  dfn?.call(); // LINT

  (a.call)(); // OK
  (f.call)(); // OK
  (d.call)(); // LINT
  (df.call)(); // LINT

  a.call; // OK
  an?.call; // OK
  f.call; // OK
  fn?.call; // OK
  d.call; // LINT
  df.call; // OK
  dfn?.call; // OK
}

main() {
  A a = A();
  F f = fun;
  test(a, a, a, a, a, a, a);
  test(a, a, f, f, f, f, f);
}

The cases marked // OK ! are the ones which are currently flagged by the lint but should not be. All the other cases are correct, AFAICS.

Metadata

Metadata

Assignees

Labels

devexp-linterIssues with the analyzer's support for the linter packagelegacy-area-analyzerUse area-devexp instead.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions