Skip to content
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

default: doesn't trigger UNREACHABLE_SWITCH_CASE hint #54575

Closed
stereotype441 opened this issue Jan 10, 2024 · 0 comments
Closed

default: doesn't trigger UNREACHABLE_SWITCH_CASE hint #54575

stereotype441 opened this issue Jan 10, 2024 · 0 comments
Assignees
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@stereotype441
Copy link
Member

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.

@stereotype441 stereotype441 added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. analyzer-warning Issues with the analyzer's Warning codes labels Jan 10, 2024
@pq pq added P2 A bug or feature request we're likely to work on analyzer-spec Issues with the analyzer's implementation of the language spec labels Jan 11, 2024
@srawlins srawlins added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Apr 5, 2024
@stereotype441 stereotype441 self-assigned this Aug 5, 2024
copybara-service bot pushed a commit that referenced this issue Aug 16, 2024
I'm currently working on a fix to the analyzer that will cause
unreachable default clauses to be properly flagged as a warning
(#54575). To avoid a bot
failure when the fix lands, these unreachable default clauses need to
be removed.

Bug: #54575
Change-Id: I35cc2be79d918a8f6ee7b388cf97044f0196b932
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380961
Commit-Queue: Paul Berry <[email protected]>
Reviewed-by: Nate Biggs <[email protected]>
Auto-Submit: Paul Berry <[email protected]>
copybara-service bot pushed a commit that referenced this issue Aug 19, 2024
I'm currently working on a fix to the analyzer that will cause
unreachable default clauses to be properly flagged as a warning
(#54575). To avoid a bot
failure when the fix lands, this unreachable default clause needs to
be removed.

Bug: #54575
Change-Id: I8b44341fad3146d4fdd64831e263513fd5092102
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380075
Commit-Queue: Tess Strickland <[email protected]>
Reviewed-by: Tess Strickland <[email protected]>
Auto-Submit: Paul Berry <[email protected]>
copybara-service bot pushed a commit that referenced this issue Aug 19, 2024
I'm currently working on a fix to the analyzer that will cause
unreachable default clauses to be properly flagged as a warning
(#54575). To avoid a bot
failure when the fix lands, these unreachable default clauses need to
be removed.

Bug: #54575
Change-Id: If97416de0f13bc66cf60a1da7df295838a8d18a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380962
Reviewed-by: Johnni Winther <[email protected]>
Commit-Queue: Paul Berry <[email protected]>
copybara-service bot pushed a commit that referenced this issue Aug 19, 2024
I'm currently working on a fix to the analyzer that will cause
unreachable default clauses to be properly flagged as a warning
(#54575). To avoid a bot
failure when the fix lands, this unreachable default clause needs to
be removed.

Bug: #54575
Change-Id: Iba0d32cf28f716f790c68a88b209420871845db8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380963
Commit-Queue: Paul Berry <[email protected]>
Auto-Submit: Paul Berry <[email protected]>
Reviewed-by: Mark Zhou <[email protected]>
stereotype441 added a commit to stereotype441/devtools that referenced this issue Aug 23, 2024
The Dart analyzer will soon be changed so that if the `default` clause
of a `switch` statement is determined to be unreachable by the
exhaustiveness checker, a new warning of type
`unreachable_switch_default` will be issued. This parallels the
behavior of the existing `unreachable_switch_case` warning, which is
issued whenever a `case` clause of a `switch` statement is determined
to be unreachable. For details see
dart-lang/sdk#54575.

This PR deletes unreachable `default` clauses from `devtools` now, to
avoid a spurious warning when the analyzer change lands.
stereotype441 added a commit to stereotype441/webdev that referenced this issue Aug 26, 2024
The Dart analyzer will soon be changed so that if the `default` clause
of a `switch` statement is determined to be unreachable by the
exhaustiveness checker, a new warning of type
`unreachable_switch_default` will be issued. This parallels the
behavior of the existing `unreachable_switch_case` warning, which is
issued whenever a `case` clause of a `switch` statement is determined
to be unreachable. For details see
dart-lang/sdk#54575.

This PR deletes unreachable `default` clauses from `webdev/dwds` now,
to avoid a spurious warning when the analyzer change lands.
stereotype441 added a commit to flutter/devtools that referenced this issue Aug 26, 2024
The Dart analyzer will soon be changed so that if the `default` clause
of a `switch` statement is determined to be unreachable by the
exhaustiveness checker, a new warning of type
`unreachable_switch_default` will be issued. This parallels the
behavior of the existing `unreachable_switch_case` warning, which is
issued whenever a `case` clause of a `switch` statement is determined
to be unreachable. For details see
dart-lang/sdk#54575.

This PR deletes unreachable `default` clauses from `devtools` now, to
avoid a spurious warning when the analyzer change lands.
stereotype441 added a commit to stereotype441/photo_view that referenced this issue Aug 27, 2024
The Dart analyzer will soon be changed so that if the `default` clause
of a `switch` statement is determined to be unreachable by the
exhaustiveness checker, a new warning of type
`unreachable_switch_default` will be issued. This parallels the
behavior of the existing `unreachable_switch_case` warning, which is
issued whenever a `case` clause of a `switch` statement is determined
to be unreachable. For details see
dart-lang/sdk#54575.

This PR deletes unreachable `default` clauses from `photo_view` now,
to avoid a spurious warning when the analyzer change lands.
stereotype441 added a commit to stereotype441/dart-sass that referenced this issue Aug 28, 2024
The Dart analyzer will soon be changed so that if the `default` clause
of a `switch` statement is determined to be unreachable by the
exhaustiveness checker, a new warning of type
`unreachable_switch_default` will be issued. This parallels the
behavior of the existing `unreachable_switch_case` warning, which is
issued whenever a `case` clause of a `switch` statement is determined
to be unreachable. For details see
dart-lang/sdk#54575.

This PR deletes an unreachable `default` clause from `dart-sass` now,
to avoid a spurious warning when the analyzer change lands.
nex3 pushed a commit to sass/dart-sass that referenced this issue Aug 30, 2024
The Dart analyzer will soon be changed so that if the `default` clause
of a `switch` statement is determined to be unreachable by the
exhaustiveness checker, a new warning of type
`unreachable_switch_default` will be issued. This parallels the
behavior of the existing `unreachable_switch_case` warning, which is
issued whenever a `case` clause of a `switch` statement is determined
to be unreachable. For details see
dart-lang/sdk#54575.

This PR deletes an unreachable `default` clause from `dart-sass` now,
to avoid a spurious warning when the analyzer change lands.
renancaraujo pushed a commit to bluefireteam/photo_view that referenced this issue Sep 4, 2024
The Dart analyzer will soon be changed so that if the `default` clause
of a `switch` statement is determined to be unreachable by the
exhaustiveness checker, a new warning of type
`unreachable_switch_default` will be issued. This parallels the behavior
of the existing `unreachable_switch_case` warning, which is issued
whenever a `case` clause of a `switch` statement is determined to be
unreachable. For details see
dart-lang/sdk#54575.

This PR deletes unreachable `default` clauses from `photo_view` now, to
avoid a spurious warning when the analyzer change lands.
stereotype441 added a commit to dart-lang/webdev that referenced this issue Sep 4, 2024
The Dart analyzer will soon be changed so that if the `default` clause
of a `switch` statement is determined to be unreachable by the
exhaustiveness checker, a new warning of type
`unreachable_switch_default` will be issued. This parallels the
behavior of the existing `unreachable_switch_case` warning, which is
issued whenever a `case` clause of a `switch` statement is determined
to be unreachable. For details see
dart-lang/sdk#54575.

This PR deletes unreachable `default` clauses from `webdev/dwds` now,
to avoid a spurious warning when the analyzer change lands.
stereotype441 added a commit to stereotype441/devtools that referenced this issue Sep 5, 2024
The Dart analyzer will soon be changed so that if the `default` clause
of a `switch` statement is determined to be unreachable by the
exhaustiveness checker, a new warning of type
`unreachable_switch_default` will be issued. This parallels the
behavior of the existing `unreachable_switch_case` warning, which is
issued whenever a `case` clause of a `switch` statement is determined
to be unreachable. For details see
dart-lang/sdk#54575.

This PR deletes an unreachable `default` clause from `devtools` now,
to avoid a spurious warning when the analyzer change lands.
stereotype441 added a commit to flutter/devtools that referenced this issue Sep 6, 2024
The Dart analyzer will soon be changed so that if the `default` clause
of a `switch` statement is determined to be unreachable by the
exhaustiveness checker, a new warning of type
`unreachable_switch_default` will be issued. This parallels the
behavior of the existing `unreachable_switch_case` warning, which is
issued whenever a `case` clause of a `switch` statement is determined
to be unreachable. For details see
dart-lang/sdk#54575.

This PR deletes an unreachable `default` clause from `devtools` now,
to avoid a spurious warning when the analyzer change lands.
stereotype441 added a commit to flutter/engine that referenced this issue Sep 6, 2024
The Dart analyzer will soon be changed so that if the `default` clause
of a `switch` statement is determined to be unreachable by the
exhaustiveness checker, a new warning of type
`unreachable_switch_default` will be issued. This parallels the behavior
of the existing `unreachable_switch_case` warning, which is issued
whenever a `case` clause of a `switch` statement is determined to be
unreachable.

Before adding the new warning to the analyzer, code in the engine needs
to first be updated to eliminate these unreachable `default` clauses, so
that the warning won't cause builds to break.

For more information, see
dart-lang/sdk#54575.
stereotype441 added a commit to stereotype441/drift that referenced this issue Sep 9, 2024
The Dart analyzer will soon be changed so that if the `default` clause
of a `switch` statement is determined to be unreachable by the
exhaustiveness checker, a new warning of type
`unreachable_switch_default` will be issued. This parallels the
behavior of the existing `unreachable_switch_case` warning, which is
issued whenever a `case` clause of a `switch` statement is determined
to be unreachable. For details see
dart-lang/sdk#54575.

This PR deletes unreachable `default` clauses from `drift` now,
to avoid spurious warnings when the analyzer change lands.
simolus3 added a commit to simolus3/drift that referenced this issue Sep 9, 2024
The Dart analyzer will soon be changed so that if the `default` clause
of a `switch` statement is determined to be unreachable by the
exhaustiveness checker, a new warning of type
`unreachable_switch_default` will be issued. This parallels the
behavior of the existing `unreachable_switch_case` warning, which is
issued whenever a `case` clause of a `switch` statement is determined
to be unreachable. For details see
dart-lang/sdk#54575.

This PR deletes unreachable `default` clauses from `drift` now,
to avoid spurious warnings when the analyzer change lands.
---------

Co-authored-by: Simon Binder <[email protected]>
jesswrd pushed a commit to jesswrd/engine that referenced this issue Sep 11, 2024
…4996)

The Dart analyzer will soon be changed so that if the `default` clause
of a `switch` statement is determined to be unreachable by the
exhaustiveness checker, a new warning of type
`unreachable_switch_default` will be issued. This parallels the behavior
of the existing `unreachable_switch_case` warning, which is issued
whenever a `case` clause of a `switch` statement is determined to be
unreachable.

Before adding the new warning to the analyzer, code in the engine needs
to first be updated to eliminate these unreachable `default` clauses, so
that the warning won't cause builds to break.

For more information, see
dart-lang/sdk#54575.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-spec Issues with the analyzer's implementation of the language spec analyzer-warning Issues with the analyzer's Warning codes area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants