Skip to content

Analyzer issue in case of constant constructor and mixin application #59796

@sgrekhov

Description

@sgrekhov

The code below produces an error in the analyzer but works without any issue in VM.

class C {
  const C();
}

mixin M on C {
  static const M instance = MC(); // Analyzer error.  The constructor being called isn't a const constructor.
}

class MC = C with M;

main() {
  print(M.instance); 
}

According to the Dart language specification (12.3 Mixin Application) if C has a constant constructor and M declares no instance variables then default constructor of MC is also a constant constructor. So, I believe, that CFE is right here and the analyzer produces a wrong error. Please confirm.

If Sq is a generative const constructor, and MC does not declare any instance variables, Cq is also a const constructor

Dart SDK version: 3.7.0-264.0.dev (dev) (Wed Dec 18 00:02:57 2024 -0800) on "windows_x64"

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-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