switch_ case_ completes_ normally
Details about the 'switch_case_completes_normally' diagnostic produced by the Dart analyzer.
The 'case' shouldn't complete normally.
Description
#
The analyzer produces this diagnostic when the statements
following a
case label in a switch statement
could fall through to the next
case
or default label.
Example
#
The following code produces this diagnostic because the
case label with a value of zero (0)
falls through to the default statements:
void f(int a) {
switch (a) {
case 0:
print(0);
default:
return;
}
}
Common fixes
#
Change the flow of control so that the case won't
fall through. There are several ways that this can be done,
including adding one of the following at the end of the
current list of statements:
- a
returnstatement, - a
throwexpression, - a
breakstatement, - a
continue, or -
an invocation of a function or method whose return type is
Never.
除非另有说明,文档之所提及适用于 Dart 3.12.2 版本报告页面问题.