-
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: iota can be shaddowed in functions, but can't in top level. #20219
Comments
|
iota is predeclared in builtin package. |
The scope of package level const declarations is the entire package. The scope of function-level const declarations begins after the declaration. After explicit renaming, your code is:
|
The program in my first comment is two programs in fact 1: package main
func g() {
const iota = iota // ok
}
func main(){} 2: package main
const iota = iota // constant definition loop
func main(){} they should be consistent. |
That's correct. gccgo and go/types emit the same errors. This is working according to spec. |
Which paragraph in spec? |
|
but iota is a predeclared constant. |
Please see https://github.com/golang/go/wiki/Questions. |
I think you misunderstand the spec.
|
@go101 iota is predeclared, but in your program you're not referring to it:
The first thing that happens is that you declare a new identifier If you're inside a function, the starting point of the scope of identifier The difference between the two is simply the point where visibility of the newly declared identifier starts. At the package level it's right away; inside functions it's always after the declaration (except for types). |
Because RHS is defined.
Because RHS is undefined. |
ok, this is really subtle. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.8.1 linux/amd64
What did you do?
The text was updated successfully, but these errors were encountered: