Skip to content

spec: go not as smart about log.Panicf() as it is about panic() #10037

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ellisonch opened this issue Feb 28, 2015 · 3 comments
Closed

spec: go not as smart about log.Panicf() as it is about panic() #10037

ellisonch opened this issue Feb 28, 2015 · 3 comments

Comments

@ellisonch
Copy link

Go is quite happy with the following program:

package main

import "fmt"
// import "log"

func foo(x int) int {
    if x == 0 {
        return 0
    }
    // log.Panicf("Not yet handling case %d", x)
    panic(fmt.Sprintf("Not yet handling case %d", x))
}

func main() {
    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

@bradfitz
Copy link
Contributor

This is working as defined by the spec: http://golang.org/ref/spec#Terminating_statements

@mikioh 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
@ellisonch
Copy link
Author

Where should I post issues about the spec? It seems like having the concept of NoReturn would be a nice extension of the terminating statement idea.

@bradfitz
Copy link
Contributor

bradfitz commented Mar 1, 2015

Generally language change requests are first discussed at https://groups.google.com/forum/#!forum/golang-nuts

@golang golang locked and limited conversation to collaborators Jun 25, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants