Skip to content
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

proposal: vet should catch shadowing of predeclared identifiers #33567

Open
seebs opened this issue Aug 9, 2019 · 2 comments

Comments

@seebs
Copy link
Contributor

commented Aug 9, 2019

(Related: #31064, #14494)

What version of Go are you using (go version)?

1.12, but N/A

Does this issue reproduce with the latest release?

I believe so?

What operating system and processor architecture are you using (go env)?

N/A

What did you do?

Horrible monstrous things. Examples:

const iota = 0
type int struct{}
var nil = "haha"

Okay, fine, those are stupid. But you know what I've done unintentionally?

...
len := a -b
...
for i := 0; i < len(x); i++ {
...

and then get confused by the weird error message about len not being a function.

What did you expect to see?

I think redeclaring predeclared identifiers should be an error. Or, since that's probably impractical, it should be a thing in go vet.

What did you see instead?

Really weird and misleading error messages when I forget that something is a predeclared identifier. I've hit this most often with len, because that's a natural variable name and when I'm naming something that I'm usually not thinking about the function.

@gopherbot gopherbot added this to the Proposal milestone Aug 9, 2019

@gopherbot gopherbot added the Proposal label Aug 9, 2019

@bcmills

This comment has been minimized.

Copy link
Member

commented Aug 9, 2019

See also #31064 and #21606.

@robpike

This comment has been minimized.

Copy link
Contributor

commented Aug 9, 2019

This particular case of shadowing is no different in kind from the general issue. We should be able to close this in deference to the ones linked above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.