Skip to content

Analyzer incorrectly resolves unqualified identifiers in classes #38032

Closed
@leafpetersen

Description

@leafpetersen

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4dart-model-analyzer-specIssues with the analyzer's implementation of the language speclegacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions