Skip to content

False positive prefer_const_constructors_in_immutables with enum comparison in assert #58360

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
a14n opened this issue Mar 24, 2021 · 0 comments
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-linter Issues with the analyzer's support for the linter package linter-false-positive linter-set-flutter P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@a14n
Copy link
Contributor

a14n commented Mar 24, 2021

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

@srawlins srawlins added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) linter-false-positive labels Jun 18, 2021
@srawlins srawlins added the P2 A bug or feature request we're likely to work on label Oct 26, 2022
@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 19, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 19, 2024
@bwilkerson bwilkerson added area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. and removed legacy-area-analyzer Use area-devexp instead. labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-linter Issues with the analyzer's support for the linter package linter-false-positive linter-set-flutter P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants