V8009. Two or more 'case' branches perform the same actions.
The analyzer has detected that multiple case clauses of the switch statement contain the same code. This error may occur as a result of copying code. This may cause part of the program logic to stop working.
The example:
switch msg {
case "start":
Start()
case "stop":
Start()
}
In some cases, different case labels require the same actions. To enhance readability, the implementation can be streamlined:
switch msg {
case "start":
Start()
case "stop":
Stop()
}
Identical case bodies may be intentional, but they can still make the code ambiguous.
The example:
switch msg {
case "start":
Start()
case "begin":
Start()
default:
Stop()
}
In this example, the same code is used for the start and begin cases, which may later be ambiguous.
To enhance clarity, the code can be rewritten as follows:
switch msg {
case "start", "begin":
Start()
default:
Stop()
}