Skip to content

Commit

Permalink
[camerax] Ignore new unreachable_switch_default warning. (flutter#7592
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 the camerax package. This change
adds `ignore` comments to avoid a spurious warning.
  • Loading branch information
stereotype441 authored Sep 9, 2024
1 parent d07c025 commit 03623b6
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}');
Expand Down

0 comments on commit 03623b6

Please sign in to comment.