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
package main
import"fmt"// import "log"funcfoo(xint) int {
ifx==0 {
return0
}
// log.Panicf("Not yet handling case %d", x)panic(fmt.Sprintf("Not yet handling case %d", x))
}
funcmain() {
foo(0)
}
It understands that panic() is a "NoReturn" function, and so it eliminates foo()'s responsibility of returning an int in that case. It compiles and runs. However, if you swap the panic() with the log.Panicf() line (and of course swap the imports), go now complains:
.\panic.go:12: missing return at end of function
It seems that something needs to inform the compiler that log.Panicf() (and other similar functions) are also NoReturn.
$ go version
go version go1.4.1 windows/amd64
The text was updated successfully, but these errors were encountered:
mikioh
changed the title
go not as smart about log.Panicf() as it is about panic()
spec: go not as smart about log.Panicf() as it is about panic()
Feb 28, 2015
Go is quite happy with the following program:
It understands that panic() is a "NoReturn" function, and so it eliminates
foo()
's responsibility of returning an int in that case. It compiles and runs. However, if you swap thepanic()
with thelog.Panicf()
line (and of course swap the imports), go now complains:It seems that something needs to inform the compiler that
log.Panicf()
(and other similar functions) are also NoReturn.$ go version
go version go1.4.1 windows/amd64
The text was updated successfully, but these errors were encountered: