-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/compile: the compiler should probably recognize runtime.Goexit #37193
Comments
The relevant bit of the spec is https://golang.org/ref/spec#Terminating_statements. I’d personally be reluctant to add runtime.Goexit; everything else in that list is lower level. It is important for vet to use the same set of terminating statements as the compiler. Otherwise you’ll be forced to add a terminating statement in some cases (like this) to make your code compile but vet will then complain about it. |
The |
/cc @randall77 @griesemer per owners. |
The definition of "terminating statements" is based strictly on properties of the language spec (which are unlikely to change), not APIs (which may change). Also, even if we added More precisely, Not really a proposal, but leaving open for a decision by the proposal review commitee. |
I've found a bunch of times where I call |
I also hit this case while working with |
We made a decision a long time ago that the language is going to require a |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
https://play.golang.org/p/SZZ4gDss0DK
What did you expect to see?
The program to be compiled.
What did you see instead?
The Go compiler does not know that
runtime.Goexit
causes the function to exit, so thereturn
statement is unreachable and not required.Of course there are similar functions like
os.Exit
, butGoexit
is part of the runtime, so it should probably be recognized by the compiler.On the other hand,
vet
should know aboutruntime.Goexit
and should report that the statements afterGoexit()
are not reachable.The
compile
orvet
commands should also report an error if a function used in thego
statement has a non empty result in the signature, but this is a different issue and probably there is a reason why it does not report an error.The text was updated successfully, but these errors were encountered: