V8010. Two or more 'case' branches have equivalent expressions.
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:
....
}