Skip to content

Wrong error in the analyzer in case of ternary operator and constant evaluation #60448

Open
@sgrekhov

Description

@sgrekhov

The code below produce an error in the analyzer and no issues in CFE

class C {
  static C one = const C(1); // Note, one is not a constant
  static const C two = const C(2);
  final int v;
  const C(this.v);
}

main() {
  const c = 2 > 1 ? C.two : C.one; // Analyzer error. Const variables must be initialized with a constant value.
}

There should be no this error in the analyzer.

cc @eernstg to confirm.

Metadata

Metadata

Assignees

No one assigned

    Labels

    analyzer-constantsarea-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.model-const-evalImplementation of constant evaluation in analyzer/cfestatus-pending

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions