cmd/compile: mention shadowing of predeclared identifiers in errors they cause
#33,567 opened on Aug 9, 2019
Repository metrics
- Stars
- (133,883 stars)
- PR merge metrics
- (No merged PRs in 30d)
Description
(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.