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 incorrectly resolves assignment to an instance setter which shadows a toplevel method #37923

Closed
leafpetersen opened this issue Aug 20, 2019 · 4 comments
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.

Comments

@leafpetersen
Copy link
Member

The analyzer reports an error on the assignments to topLevelMethod and topLevelMethod2 in the code below. This seems incorrect by my reading of the specification:

Evaluation of an assignment $a$ of the form \code{$v$ = $e$}
proceeds as follows:
%% TODO(eernst): $d$ is defined ambiguously: both getter & setter may exist.
Let $d$ be the innermost declaration whose name is $v$ or \code{$v$=}, if it exists.
It is a compile-time error if $d$ denotes
a prefix object, type declaration, or function declaration.

There is a clear innermost declaration whose name is topLevelMethod= (topLevelMethod2=) here, unless there is something non-obvious about the terminology here. The CFE issues no error on this code.

cc @eernstg @lrhn @munificent

int get topLevelGetter => -1;
void set topLevelSetter(int _) {}
int topLevelField = -3;
int topLevelMethod(int x) => -4;
int topLevelMethod2(int x) => -4;

int _storeTo;

class E2  {
  void set topLevelGetter(int x) { _storeTo = x; }
  void set topLevelField(int x) { _storeTo = x; }
  void set topLevelMethod(int x) { _storeTo = x; }
  static void set topLevelMethod2(int x) { _storeTo = x; }
  void test() {
    topLevelGetter = 42;
    topLevelField = 42;
    topLevelMethod = 42;
    topLevelMethod2 = 42;
  }
}
@leafpetersen leafpetersen added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Aug 20, 2019
@leafpetersen
Copy link
Member Author

Tests for this landed here.

@leafpetersen
Copy link
Member Author

@bwilkerson @stereotype441 Is this a blocker for the release, or do you plan to fix this later with the same issue in classes?

@leafpetersen
Copy link
Member Author

Ah never, mind, this is the issue for classes.

@srawlins srawlins added the analyzer-spec Issues with the analyzer's implementation of the language spec label Jun 16, 2020
@srawlins
Copy link
Member

The analyzer no longer reports an errors with this code (if you give an initializer to _storeTo.

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.
Projects
None yet
Development

No branches or pull requests

2 participants