Go code that cannot be executed is a logical error, and therefore it is pretty difficult to reveal it with developers or a normal execution of the Go compiler. Put simply, there is nothing wrong with unreachable code, apart from the fact that there is no way for this code to get executed.
Take a look at the following Go code, which is saved as cannotReach.go:
package main import ( "fmt" ) func f1() int { fmt.Println("Entering f1()") return -10 fmt.Println("Exiting f1()") return -1 } func f2() int { if true { return 10 } fmt.Println("Exiting f2()") return 0 } func main() { fmt.Println(f1()) fmt.Println("Exiting program...") }
There is nothing syntactically incorrect with the Go code of cannotReach.go. As a result, you can execute...