Skip to content

Commit

Permalink
[url_launcher] Ignore new unreachable_switch_default warning. (#7487)
Browse files Browse the repository at this point in the history
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.

In the vast majority of cases, the most reasonable way to address the
warning is to remove the unreachable `default` clause. However, in a few
rare cases, it makes sense to keep the `default` clause, because it's
intentionally future-proofing the code in case new possible values are
added to the enum being switched on.

Three of these rare cases crop up in flutter/packages. This change adds
`ignore` comments to avoid a spurious warning.
  • Loading branch information
stereotype441 authored Aug 26, 2024
1 parent f61a98a commit 6c12c88
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class UrlLauncherAndroid extends UrlLauncherPlatform {
case PreferredLaunchMode.platformDefault:
// Intentionally treat any new values as platformDefault; see comment in
// supportsMode.
// ignore: no_default_cases
// ignore: no_default_cases, unreachable_switch_default
default:
// By default, open web URLs in the application.
inApp = url.startsWith('http:') || url.startsWith('https:');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class UrlLauncherIOS extends UrlLauncherPlatform {
// Intentionally treat any new values as platformDefault; support for any
// new mode requires intentional opt-in, otherwise falling back is the
// documented behavior.
// ignore: no_default_cases
// ignore: no_default_cases, unreachable_switch_default
default:
// By default, open web URLs in the application.
inApp = url.startsWith('http:') || url.startsWith('https:');
Expand Down Expand Up @@ -110,7 +110,7 @@ class UrlLauncherIOS extends UrlLauncherPlatform {
// Default is a desired behavior here since support for new modes is
// always opt-in, and the enum lives in a different package, so silently
// adding "false" for new values is the correct behavior.
// ignore: no_default_cases
// ignore: no_default_cases, unreachable_switch_default
default:
return false;
}
Expand Down

0 comments on commit 6c12c88

Please sign in to comment.