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

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

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

V8010. Two or more 'case' branches have equivalent expressions.

Apr 03 2026

The analyzer detected identical expressions in case. This error may occur as a result of copy-pasted code. As a result, not all of the intended options may be handled in the switch statement, and some branches may become unreachable.

The example:

const (
    MONDAY    = 1
    TUESDAY   = 2
    WEDNESDAY = 3
    THURSDAY  = 4
    FRIDAY    = 5
)

switch {
case day == MONDAY:
  ....  
case day == TUESDAY:
  ....
case day == WEDNESDAY:
  ....
case day == THURSDAY:
  ....
case day == MONDAY:
  ....
}

In this example, the day == MONDAY condition is used twice. Consequently, the code inside the last case will be unreachable. Instead of the second identical expression, the day == FRIDAY is intended to be used.

The fixed code:

switch {
case day == MONDAY:
  ....  
case day == TUESDAY:
  ....
case day == WEDNESDAY:
  ....
case day == THURSDAY:
  ....
case day == FRIDAY:
  ....
}