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] An explicitly instantiated top level function tearoff is parsed as an instance creation expression #47005

Closed
stereotype441 opened this issue Aug 26, 2021 · 1 comment
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

With the constructor-tearoffs experiment enabled, the following code is accepted by the CFE but rejected by the analyzer:

typedef X<_> = Class;

class Class {}

int f2<X, Y>([_]) => 0;

extension <T extends Object?> on T {
  T get self => this;
  Object? call<R, S>([_]) => null;
}

main() {
  f2<X, X>.self();
}

(Note: this code is based on https://dart-review.googlesource.com/c/sdk/+/211420)

The error message (at the line f2<X, X>.self();) is The name 'f2' isn't a class. (creation_with_non_type).

It seems like the analyzer is treating f2<X, X>.self() as an instance creation expression (understandable, because it looks like one), but in fact it is an explicitly instantiated tearoff of the top level function f2, followed by an invocation of the extension getter self, followed by an implicit invocation of the extension method call. This should all be allowed provided that the constructor-tearoffs experiment is enabled.

Note: this seems similar to #46721 (which is marked as fixed), but the thing being torn off is a top level function rather than a method.

@stereotype441 stereotype441 added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Aug 26, 2021
@eernstg
Copy link
Member

eernstg commented Aug 26, 2021

Here is another issue which is similar: #46887.

That issue is area-front-end, and has been fixed in ce4e770, but the analyzer (from 7959f03) reports an error in the following program as well:

String f(a, [b]) => "$a, $b";

String a<T1, T2>(int x) {
  return "a<$T1, $T2>($x)";
}

typedef b = int;
typedef c = String;

main() {
  print('The following should be equal:');
  print('  ${a<b, c>}, null');
  print('  ${f(a<b, c>.toString())}');
}
ERROR|COMPILE_TIME_ERROR|CREATION_WITH_NON_TYPE|/usr/local/google/home/eernst/lang/dart/scratch/202108/n029.dart|13|16|1|The name 'a' isn't a class.

Cf. https://github.com/dart-lang/co19/blob/aff1a334d7875e465c2f43e1b38774512fbb4ba4/LanguageFeatures/Constructor-tear-offs/ambiguities_A08_t02.dart, where this construct occurs.

@scheglov scheglov added the P2 A bug or feature request we're likely to work on label Aug 26, 2021
@scheglov scheglov added the analyzer-spec Issues with the analyzer's implementation of the language spec label Aug 26, 2021
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

4 participants