Skip to content

default: doesn't trigger UNREACHABLE_SWITCH_CASE hint #54575

Closed
@stereotype441

Description

Consider the following code:

sealed class A {}
class B extends A {}
class C extends A {}

String f(A x) {
  switch (x) {
    case B():
      return 'B';
    case C():
      return 'C';
    case _:
      return 'Some other subclass of A (impossible)';
  }
}

This produces the analyzer hint:

info - test.dart:11:5 - This case is covered by the previous cases. Try removing the case clause, or restructuring the preceding patterns. - unreachable_switch_case

Which seems reasonable.

However, if I replace case _: with default:, then the analyzer doesn't report any issues.

This seems wrong to me. case _: and default: have exactly the same runtime behavior. They should lead to the same hints.

Metadata

Assignees

Labels

P2A bug or feature request we're likely to work onanalyzer-specIssues with the analyzer's implementation of the language specanalyzer-warningIssues with the analyzer's Warning codesarea-analyzerUse area-analyzer for Dart analyzer issues, including the analysis server and code completion.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions