Skip to content

[cfe] Surprising error message for expression in guard #51898

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
eernstg opened this issue Mar 30, 2023 · 0 comments
Closed

[cfe] Surprising error message for expression in guard #51898

eernstg opened this issue Mar 30, 2023 · 0 comments
Assignees
Labels
improve-diagnostics Related to the quality of diagnostic messages legacy-area-front-end Legacy: Use area-dart-model instead.

Comments

@eernstg
Copy link
Member

eernstg commented Mar 30, 2023

Consider the following program:

void main() {
  int d = 1;
  var x = false;
  switch (d) {
    case 1 when x = true:
      print('OK!');
  }
}

This program is rejected by the CFE (3.0.0-366.0.dev) with a surprising error message:

lib/main.dart:6:19:
Error: Not a constant expression.
    case 1 when x = true:
                  ^

This error message is surprising because there is no requirement that the expression in a guard must be constant (indeed, that wouldn't make sense).

@eernstg eernstg added legacy-area-front-end Legacy: Use area-dart-model instead. improve-diagnostics Related to the quality of diagnostic messages labels Mar 30, 2023
@johnniwinther johnniwinther self-assigned this Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improve-diagnostics Related to the quality of diagnostic messages legacy-area-front-end Legacy: Use area-dart-model instead.
Projects
None yet
Development

No branches or pull requests

2 participants