-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/compile: compiler does vet things #54019
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
Comments
This breaks expectations and does prevent some valid code from compiling. |
I plead to reopen this issue, for three reasons:
package main
import "fmt"
func g() (int, error) {
return 0, fmt.Errorf("not implemented")
}
func f() (err error) {
if n, err := g(); err == nil {
return
} else {
return fmt.Errorf("%w: %d", err, n)
}
}
func main() {
fmt.Println(f())
} Just let compilers do compiler things is a good philosophy. |
@go101 As @seankhliao said, the language spec explicitly calls this out as an implementation restriction. The implementation restriction was added to the tools in https://go.dev/cl/5245056. That predates the proposal process; it was part of the set of changes made for the release of Go 1. You can see it mentioned at https://docs.google.com/document/pub?id=1ny8uI-_BHrDCZv_zNBSthNKAMX_fR_0dc6epA6lztRE which is linked from the blog entry https://go.dev/blog/go1-preview. I don't think there is any new information since then, so I don't think we are going to change that decision. |
The problem is the restriction might do false positive things, which is okay for govet, but is weird for go compilers. Personally, I don't get why this warning is any more harmful than the other warnings reported by govet. So I don't understand why it is promoted to the compiler level.
If this breaks user expectations and causes unhappy user experiences is not new information ... |
BTW, there is a poll: https://twitter.com/go100and1/status/1578997940487876608, which shows 2/3 voters think it should compile. |
The compiler gives an error on this code because we observed that people thought they could use a naked It's true that we might make a different decision today, but I think that given that the compiler has acted this way for 10 years, we need a really strong reason to change it. And "weird for Go compilers" is a valid reason, but it's not a strong reason. |
This is also true for many cases reported by vet. And this decision was made before 1.0, so I doubt the validity of the reason. At least for me, it is not true. Personally, I think this is a “draw legs on a snake” thing, because it breaks user expectations, which is a strong enough reason. |
What version of Go are you using (
go version
)?Also for many previous versions.
Does this issue reproduce with the latest release?
Yes
What did you do?
What did you expect to see?
Complies okay.
What did you see instead?
Fails to compile.
The text was updated successfully, but these errors were encountered: