Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
eernstg opened this issue Jul 26, 2021 · 1 comment
Assignees
Labels
legacy-area-front-end Legacy: Use area-dart-model instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@eernstg
Copy link
Member

eernstg commented Jul 26, 2021

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).

@eernstg eernstg added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) legacy-area-front-end Legacy: Use area-dart-model instead. labels Jul 26, 2021
@johnniwinther johnniwinther self-assigned this Aug 17, 2021
@johnniwinther
Copy link
Member

I think the underlying bug is the same as for #46887

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-front-end Legacy: Use area-dart-model instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

2 participants