You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can't compile a function with no return after panic.
IMHO, adding the 'panic' clause after 'throw' in the following example is a dead code and should be omitted.
package main
import"fmt"functhrow(messagestring){
panic(message)
}
funcfoo(valueint) int{
switchvalue {
case1:
return2case3:
return4
}
throw("Can't do this!")
//panic("Can't do this!") // uncomment this to compile.
}
funcmain() {
fmt.Printf("Hello world: %v", foo(1))
}
expected: code compiles. got: ./test.go:18: missing return at end of function version:
go version go1.5.1 darwin/amd64
go version go1.5.1 windows/amd64
The text was updated successfully, but these errors were encountered:
Working as intended. The compiler doesn't look into function calls (throw) to determine if a function terminates or not. The spec rules are pretty clear about this.
Can't compile a function with no return after panic.
IMHO, adding the 'panic' clause after 'throw' in the following example is a dead code and should be omitted.
expected: code compiles.
got:
./test.go:18: missing return at end of function
version:
go version go1.5.1 darwin/amd64
go version go1.5.1 windows/amd64
The text was updated successfully, but these errors were encountered: