Skip to content
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

Analyzer erroneously performs .call tearoff on expressions whose type is a nullable type variable #55734

Closed
stereotype441 opened this issue May 15, 2024 · 0 comments
Assignees
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on

Comments

@stereotype441
Copy link
Member

I'm currently trying to write up a specification for type inference within function bodies and initializer expressions, and this includes specifying when implicit .call tearoff should occur. I've discovered a difference in behavior between the analyzer and CFE.

The following code is accepted by the analyzer but rejected by the CFE:

class C {
  void call() {}
}

void Function() test<T extends C>(T? t) => t;

The analyzer accepts the code because, when considering whether to apply implicit .call tearoff to the expression t, it sees that the static type of t is T?, which is a type parameter type (with a ? suffix). It ignores the suffix and replaces the type parameter type with its bound, C. Then it sees that C contains a .call method with an appropriate type, so it inserts an implicit tearoff of .call. This is not sound, however, because t might be null.

The CFE correctly gives an error for this code.

I'll work on a fix.

@stereotype441 stereotype441 added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-spec Issues with the analyzer's implementation of the language spec labels May 15, 2024
@stereotype441 stereotype441 self-assigned this May 15, 2024
stereotype441 added a commit to stereotype441/language that referenced this issue May 15, 2024
@scheglov scheglov added the P2 A bug or feature request we're likely to work on label May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

2 participants