Skip to content

False positive prefer_const_constructors_in_immutables with enum comparison in assert #58360

Open
@a14n

Description

@a14n

The following code triggers prefer_const_constructors_in_immutables on A constructor but it shouldn't as enum comparisons are not yet allowed in asserts.

enum E { a, b }
@immutable
class A {
  A([E e = E.b]) : assert(e != E.a);  // LINT is here but it shouldn't trigger
}

It looks related to const evaluation as there's no analyzer error on the constructor if we make the constructor const though there's an error on the constructor invocation.

enum E { a, b }
@immutable
class A {
  const A([E e = E.b]) : assert(e != E.a); // no diagnostic but there should be an `invalid_constant` error for `e != E.a`
}
void main() {
  const A(); // const_evaluation_throws_exception
}

Filed also #45441

/cc @scheglov @bwilkerson

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2A bug or feature request we're likely to work onarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagelinter-false-positivelinter-set-fluttertype-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

        Participants

        @pq@srawlins@a14n@devoncarew@bwilkerson

        Issue actions

          False positive prefer_const_constructors_in_immutables with enum comparison in assert · Issue #58360 · dart-lang/sdk