Some statements (return
, break
, continue
, goto
, switch
) and throw
expressions move control flow out of the current code block. So any unlabeled statements that come after such a jump are unreachable, and either this
dead code should be removed, or the logic should be corrected.
Noncompliant code example
func add(x, y int) int {
return x + y // Noncompliant
z := x + y // dead code
}
Compliant solution
func add(x, y int) int {
return x + y // Compliant
}