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 unqualified identifiers in classes #38032

Closed
leafpetersen opened this issue Aug 27, 2019 · 2 comments
Closed

Analyzer incorrectly resolves unqualified identifiers in classes #38032

leafpetersen opened this issue Aug 27, 2019 · 2 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. P4 type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@leafpetersen
Copy link
Member

In the following example:

final int x = 3;

class A {
  int x = 3;
}

class B extends A {
  void test() {
    x = 4;
  }
}

The specification requires that the reference to x resolve to the top level definition of x, for which no setter is defined, and hence should be a static error.

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.

The CFE resolves this correctly, so there is an inconsistency between the tools. See this comment for more discussion.

See also:

cc @stereotype441 @vsmenon @Markzipan

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

eernstg commented Aug 28, 2019

Also note that the imprecision which is noted in places like the 'TODO' comment above is addressed in dart-lang/language#548, which is currently under review.

@srawlins srawlins added the analyzer-spec Issues with the analyzer's implementation of the language spec label Jun 16, 2020
@srawlins srawlins added the P4 label Jan 12, 2021
@srawlins srawlins added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Nov 16, 2021
@srawlins
Copy link
Member

srawlins commented May 1, 2023

Analyzer now produces:

'x' can't be used as a setter because it's final.

@srawlins srawlins closed this as completed May 1, 2023
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. P4 type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants