Skip to content

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

Closed
@chloestefantsova

Description

@chloestefantsova

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)

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions