The analyzer has detected that multiple case clauses of the switch statement contain the same code.
This error may occur, for example, as a result of copying code.
The example:
switch (selector) {
case "foo":
res = foo;
break;
case "bar":
res = bar;
break;
case "baz":
res = bar;
break;
}
In the "baz" case, res is assigned the value of bar instead of baz.
The fixed code:
switch (selector) {
case "foo":
res = foo;
break;
case "bar":
res = bar;
break;
case "baz":
res = baz;
break;
}
This warning may also indicate redundant code that can be improved by combining case labels.
The example of redundant code:
switch (selector) {
case "fooX":
res = foo;
break;
case "fooY":
res = foo;
break;
case "barX":
res = bar;
break;
case "barY":
res = bar;
break;
}
Although this is not an error, combining case labels can enhance code readability and reduce redundancy:
switch (selector) {
case "fooX":
case "fooY":
res = foo;
break;
case "barX":
case "barY":
res = bar;
break;
}
This diagnostic rule is classified as:
Was this page helpful?
Your message has been sent. We will email you at
If you do not see the email in your inbox, please check if it is filtered to one of the following folders: