Skip to content

Analyzer incorrectly resolves assignment to an instance setter which shadows a toplevel method #37923

@leafpetersen

Description

@leafpetersen

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;
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions