Skip to content

[analyzer] An explicitly instantiated instance method tearoff is parsed as starting with a prefix #46721

@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 (as of ef8add0) by dartanalyzer with the following error messages:

ERROR|COMPILE_TIME_ERROR|PREFIX_SHADOWED_BY_LOCAL_DECLARATION|/usr/local/google/home/eernst/lang/dart/scratch/202107/n038.dart|12|3|1|The prefix 'a' can't be used here because it is shadowed by a local declaration.
ERROR|COMPILE_TIME_ERROR|PREFIX_SHADOWED_BY_LOCAL_DECLARATION|/usr/local/google/home/eernst/lang/dart/scratch/202107/n038.dart|13|3|1|The prefix 'a' can't be used here because it is shadowed by a local declaration.

However, a is not an import prefix, it is a local variable. Presumably, the analyzer parser (or some other early step of the analysis) assumes that with constructs of the form <identifier> '.' <identifier> <typeArguments> '.', the first identifier must be an import prefix. That may have been true before constructor-tearoffs, but it isn't true with that feature, so the analyzer will need to investigate the situation more closely before it concludes that it is looking at an import prefix.

Metadata

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work ondart-model-analyzer-specIssues with the analyzer's implementation of the language speclegacy-area-analyzerUse area-devexp instead.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions