Skip to content

Analyzer has trouble analyzing function-typed type parameters. #27392

@lrhn

Description

@lrhn

Tested in dartpad.
See https://dartpad.dartlang.org/f983c5dac60898576edcbd38cadfe2cd for runnable example.

In the code:

typedef void Action<T>(T x);

class C<T, U extends Action<T>> {
  T value;
  U action;
  C(this.value, [this.action]);
  void act() { action(value); }  // <- warning here
}

the analyzer claims that "action is not a method". If I change action(value) to (action)(value) the error changes to "cannot invoke a non-function". It doesn't realize that because U extends a function type, action is a function.

In the following code:

fnum(num x) { print("num: $x"); }
fobj(Object x) { print("obj: $x"); }

main() {
  C<num, Action<num>> c = new C<int, Action<Object>>(42, fobj);  // <- warning here
  c.act();
  c.action = fnum;
  c.value = 1.0;
  c.act();
}

strong mode has no problem, but non-strong-mode says that:

A value of type 'C<int, Action>' cannot be assigned to a variable of type 'C<num, Action>'

It's missing the type parameters on Action, and even then it's still wrong.

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onlegacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions