From 7bd9a884f3d7d68680f89635d32a3f5f539ffbb5 Mon Sep 17 00:00:00 2001 From: Paul Berry Date: Fri, 6 Sep 2024 13:29:13 +0000 Subject: [PATCH] [camerax] 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 the camerax package. This change adds `ignore` comments to avoid a spurious warning. --- .../camera_android_camerax/lib/src/capture_request_options.dart | 2 +- packages/camera/camera_android_camerax/lib/src/live_data.dart | 2 +- .../test/capture_request_options_test.dart | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/camera/camera_android_camerax/lib/src/capture_request_options.dart b/packages/camera/camera_android_camerax/lib/src/capture_request_options.dart index 777d4a43370..8c3de00845e 100644 --- a/packages/camera/camera_android_camerax/lib/src/capture_request_options.dart +++ b/packages/camera/camera_android_camerax/lib/src/capture_request_options.dart @@ -115,7 +115,7 @@ class _CaptureRequestOptionsHostApiImpl extends CaptureRequestOptionsHostApi { // This ignore statement is safe beause this error will be useful when // a new CaptureRequestKeySupportedType is being added, but the logic in // this method has not yet been updated. - // ignore: no_default_cases + // ignore: no_default_cases, unreachable_switch_default default: throw ArgumentError(CaptureRequestOptions .getUnsupportedCaptureRequestKeyTypeErrorMessage(key)); diff --git a/packages/camera/camera_android_camerax/lib/src/live_data.dart b/packages/camera/camera_android_camerax/lib/src/live_data.dart index 9659a2068ee..1931e8169ca 100644 --- a/packages/camera/camera_android_camerax/lib/src/live_data.dart +++ b/packages/camera/camera_android_camerax/lib/src/live_data.dart @@ -185,7 +185,7 @@ class LiveDataFlutterApiImpl implements LiveDataFlutterApi { // This ignore statement is safe beause this error will be useful when // a new LiveDataSupportedType is being added, but the logic in this method // has not yet been updated. - // ignore: no_default_cases + // ignore: no_default_cases, unreachable_switch_default default: throw ArgumentError(LiveData.unsupportedLiveDataTypeErrorMessage); } diff --git a/packages/camera/camera_android_camerax/test/capture_request_options_test.dart b/packages/camera/camera_android_camerax/test/capture_request_options_test.dart index 3649369c934..5649151af92 100644 --- a/packages/camera/camera_android_camerax/test/capture_request_options_test.dart +++ b/packages/camera/camera_android_camerax/test/capture_request_options_test.dart @@ -132,7 +132,7 @@ void main() { // This ignore statement is safe beause this will test when // a new CaptureRequestKeySupportedType is being added, but the logic in // in the CaptureRequestOptions class has not yet been updated. - // ignore: no_default_cases + // ignore: no_default_cases, unreachable_switch_default default: fail( 'Option $option contains unrecognized CaptureRequestKeySupportedType key ${option.$1}');