Skip to content

Analyzer rejects const constructor in class with abstract instance variable. #54639

Open
@lrhn

Description

@lrhn

Example:

abstract class C {
  abstract int x;
  const C();  // Error here.
}
abstract class D {
  int get x;
  set x(int _);
  const D();
}
void main() {}

is rejected with the message:

error
line 3 • Can't define a const constructor for a class with non-final fields. (view docs)
Try making all of the fields final, or removing the keyword 'const' from the constructor.

This is incorrect, since the class C does not have any non-final instance variables, or instance variables at all.
It has an abstract variable declaration, but that introduces an abstract getter and setter, which are not backed by an instance variable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onanalyzer-constantsarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.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