From 6d1cf14f2dd8af4d5da0ec3bb9e8a3433d9733a3 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Fri, 23 Aug 2024 16:08:38 +0000 Subject: [PATCH] Ignore new `unreachable_switch_default` warning. 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. --- .../url_launcher_android/lib/url_launcher_android.dart | 2 +- .../url_launcher/url_launcher_ios/lib/url_launcher_ios.dart | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/url_launcher/url_launcher_android/lib/url_launcher_android.dart b/packages/url_launcher/url_launcher_android/lib/url_launcher_android.dart index 63669f847b22..7a447d5203f3 100644 --- a/packages/url_launcher/url_launcher_android/lib/url_launcher_android.dart +++ b/packages/url_launcher/url_launcher_android/lib/url_launcher_android.dart @@ -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:'); diff --git a/packages/url_launcher/url_launcher_ios/lib/url_launcher_ios.dart b/packages/url_launcher/url_launcher_ios/lib/url_launcher_ios.dart index bce7dd0586c9..bb289abc5699 100644 --- a/packages/url_launcher/url_launcher_ios/lib/url_launcher_ios.dart +++ b/packages/url_launcher/url_launcher_ios/lib/url_launcher_ios.dart @@ -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:'); @@ -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; }