Skip to content

[cfe] An explicitly instantiated instance method tearoff is not considered for extension method invocations #46719

Closed
@eernstg

Description

@eernstg

Consider the following program:

class A {
  List<X> m<X>(X x) => [x];
}

extension FunctionApplier on Function {
  void applyAndPrint(List<Object?> positionalArguments) =>
      print(Function.apply(this, positionalArguments, const {}));
}

void main() {
  var a = A();
  a.m<int>.applyAndPrint([2]);
  a.m<String>.applyAndPrint(['three']);
}

This program is rejected by the CFE (as of ef8add0) with the following error messages:

n038.dart:12:3: Error: Method not found: 'a.m.applyAndPrint'.
  a.m<int>.applyAndPrint([2]);
  ^^^^^^^^^^^^^
n038.dart:13:3: Error: Method not found: 'a.m.applyAndPrint'.
  a.m<String>.applyAndPrint(['three']);
  ^^^^^^^^^^^^^

However, the analysis should have considered a.m<int> and a.m<String> as potential receivers of an extension method invocation and detected that applyAndPrint is available and applicable, and accepted the program.

PS: The error location has a funny length, too (it's 13 in both cases, even though a.m<int> and a.m<String> do not have the same length).

Metadata

Metadata

Assignees

Labels

legacy-area-front-endLegacy: Use area-dart-model 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