Our website uses cookies to enhance your browsing experience.
Accept
to the top

Webinar: Let's make a programming language. Lexer - 29.04

>
>
>
V7008. Two or more 'case' branches...
menu mobile close menu
Additional information
toggle menu Contents

V7008. Two or more 'case' branches perform the same actions.

Apr 03 2026

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;
}