Skip to content

Analyzer should trigger an error if enum comparison is used as const expression #45441

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

Closed
a14n opened this issue Mar 24, 2021 · 2 comments
Closed
Labels
analyzer-constants legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on

Comments

@a14n
Copy link
Contributor

a14n commented Mar 24, 2021

With Dart 2.13.0 (build 2.13.0-150.0.dev) the analyzer accepts enum comparison in const expression though enum comparisons are not yet allowed in asserts.

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
}

/cc @scheglov @bwilkerson

@vsmenon vsmenon added the legacy-area-analyzer Use area-devexp instead. label Mar 24, 2021
@devoncarew devoncarew added the P2 A bug or feature request we're likely to work on label Mar 29, 2021
@srawlins
Copy link
Member

srawlins commented Sep 9, 2021

I've seen a few bugs about analyzer accepting code in assert initializers, I think also with a != operation...

@eernstg
Copy link
Member

eernstg commented Sep 9, 2021

It's on my TODO list to push on dart-lang/language#1811, which would turn e == E.a and e != E.a into constant expressions (and indeed e1 == e2 as well as e1 != e2 for any e1 that has primitive equality). So please don't rush to change the implemented behavior: It seems to be a step away from a behavior which is likely to be the specified behavior in the near future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-constants legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on
Projects
None yet
Development

No branches or pull requests

5 participants