-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
spec: prevent variable aliasing in *any* way #9818
Comments
Can't change this now. https://golang.org/doc/go1compat We will certainly revisit variable declarations and scoping rules in Go 2. |
Declare err at the outer scope and use This proposal is an incompatible language change, so |
The problem is that it's very easy to typo
Yep! |
It's fine if this waits until Go 2, just don't forget about it when it is time :) |
Even for Go 2, I think a better way is to have golint or govet detect such
cases rather than make a language change.
|
sure, as long as it automated and the developer is notified of this in some way |
the following code
will alias the
logw
variable: sincelogw
is declared outside, and in thedefault
switch case anotherlogw
is created with:=
, every default case will return anil
. Fun ensues.Go should either prevent this behaviour with a panic/error/warning or should note that the variable is initialized in an external block and properly initialize it rather than creating a new one.
The text was updated successfully, but these errors were encountered: