Skip to content

Compile-time error message about a non-joined variable usage doesn't state the reason clearly #51604

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
chloestefantsova opened this issue Mar 2, 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

@chloestefantsova
Copy link
Contributor

Consider the following program. Compiling it results in an error: the variable with name a isn't captured by every head of the switch case, so it can't be used in the case body. However, the error message produced by the CFE isn't very helpful in this case, simply stating that a is undefined in the body.

test(dynamic x) {
  switch (x) {
    case final a when a > 0:
    case 0:
    case final a:
      return a; // Error.
    default:
      return null;
  }
}
// /tmp/asdf2.dart:6:14: Error: Undefined name 'a'.
//       return a;
//              ^
@chloestefantsova chloestefantsova added legacy-area-front-end Legacy: Use area-dart-model instead. improve-diagnostics Related to the quality of diagnostic messages labels Mar 2, 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

1 participant