Skip to content

Update tests for analyzer reachability warnings #1978

@munificent

Description

@munificent

I'm updating the test runner so that we can write static error tests of unreachable case warnings (well, hints currently) from analyzer. Before this change, there's no way to write a language or co19 test that validates that analyzer reports unreachable case warnings.

This is, unsurprisingly, breaking a few tests. I've updated the ones in the Dart repo, but there are some co19 ones too:

  • co19/Language/Statements/Switch/execution_case_no_default_t01
  • co19/Language/Statements/Switch/execution_case_t01
  • co19/LanguageFeatures/Patterns/cast_A01_t02
  • co19/LanguageFeatures/Patterns/constant_A02_t15
  • co19/LanguageFeatures/Patterns/constant_A02_t18
  • co19/LanguageFeatures/Patterns/logical_or_A05_t05
  • co19/LanguageFeatures/Patterns/null_assert_A03_t01
  • co19/LanguageFeatures/Patterns/null_assert_A03_t02
  • co19/LanguageFeatures/Patterns/null_check_A02_t01
  • co19/LanguageFeatures/Patterns/object_A03_t01
  • co19/LanguageFeatures/Patterns/object_A07_t05
  • co19/LanguageFeatures/Patterns/pattern_context_A07_t02
  • co19/LanguageFeatures/Patterns/pattern_variable_sets_A01_t03
  • co19/LanguageFeatures/Patterns/pattern_variable_sets_A02_t01
  • co19/LanguageFeatures/Patterns/scope_A04_t01
  • co19/LanguageFeatures/Patterns/scope_A04_t02
  • co19/LanguageFeatures/Patterns/shared_case_scope_A01_t01
  • co19/LanguageFeatures/Patterns/shared_case_scope_A01_t02
  • co19/LanguageFeatures/Patterns/shared_case_scope_A01_t03
  • co19/LanguageFeatures/Patterns/switch_statement_A01_t01
  • co19/LanguageFeatures/Patterns/type_inference_A25_t01
  • co19/LanguageFeatures/Patterns/type_inference_A31_t01
  • co19/LanguageFeatures/Patterns/variable_A03_t02
  • co19/LanguageFeatures/Patterns/variable_A03_t03
  • co19/LanguageFeatures/Patterns/variable_A03_t05

The linked CL should give some guidance on how to fix them. It's probably some combination of:

  • If it's already a static error test, then go ahead and add expectations for the unreachability errors too. They look like:

        case A(a: Enum.a, b: false): // Unreachable
    //  ^^^^
    // [analyzer] HINT.UNREACHABLE_SWITCH_CASE
  • If the cases are intended to be unrelated and are just put into a single switch for convenience, it may be easiest to split them into separate switch statements to make the errors go away. That's what I did with invalid_const_pattern_test.dart.

Let me know if you have any questions or if there's anything I can do to help. As always, thanks. :)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions