Skip to content

Report mismatching pattern variables errors on the first use of the variable #51929

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 Apr 3, 2023 · 0 comments
Assignees
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.

Comments

@chloestefantsova
Copy link
Contributor

Currently the CFE reports the mismatching pattern variables errors on the first of the mismatching variables:

test(dynamic x) {
  switch (x) {
    case int y:
    case String y:
      return y;
    default:
      return null;
  }
}
/tmp/qwerty3.dart:3:14: Error: Variable pattern 'y' doesn't have the same type or finality in all cases.
    case int y:
             ^

The preferable way is to report the error on the first use of the joint variable, similarly to the Analyzer.

Analyzing /tmp/qwerty3.dart...
  error • The variable 'y' doesn't have the same type and/or finality in all cases that share this body. • /tmp/qwerty3.dart:5:14 • invalid_pattern_variable_in_shared_case_scope
1 error found.

The following is the example of the affected tests.

co19/LanguageFeatures/Patterns/shared_case_scope_A01_t01 MissingCompileTimeError (expected Pass)
language/patterns/shared_case_variable_error_test MissingCompileTimeError (expected Pass)
@chloestefantsova chloestefantsova added the legacy-area-front-end Legacy: Use area-dart-model instead. label Apr 3, 2023
@chloestefantsova chloestefantsova self-assigned this Apr 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-front-end Legacy: Use area-dart-model instead.
Projects
None yet
Development

No branches or pull requests

1 participant