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: more helpful "is not a type" error when variable shadows type #23065
Comments
The error message is correct: at the point of the erroneous declaration, Any suggestions on what a more informative error message would look like? |
@ianlancetaylor Ah, I wasn't aware that variable bindings and types were intended to share the same namespace. In that case, perhaps issue a warning when a variable name shadows a type name or vice versa? If not that, then perhaps this specific error could be modified to look at the shadowed names and see if any of them is a type, and give an appropriate hint? I haven't looked at how Go's name resolution works, so I'm not sure how hard that would be in practice, but I'd be happy to try and put a PR together if one of these options sounds good to you. |
Go doesn't have any warnings, intentionally. As stated in the FAQ:
|
@bradfitz I didn't mean to suggest some greater internal policy change-- do you have an alternative that you would prefer to see? Erroring on bindings-shadowing-types is obviously a breaking change and therefore a non-option. I suppose that leaves my second suggestion:
|
I'd also be fine closing this as "WONTFIX" if you think such a change is unwanted. |
A better error sounds fine. Go does strive to have readable and helpful errors. I've retitled and relabeled this bug. It's not targeted towards any release, meaning anybody can send a fix whenever. |
Change https://golang.org/cl/84479 mentions this issue: |
Change https://golang.org/cl/172357 mentions this issue: |
What version of Go are you using (
go version
)?Current playground version.
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?Unknown (plaground).
What did you do?
The following code compiles with
fancyMap is not a type
errors in bothfoo
andfoo2
(playground):What did you expect to see?
Successful compilation or a more informative error message.
What did you see instead?
Poor/incorrect error message. Simply renaming the
fancyMap
variable fixes the problem, but the error message is incorrect:fancyMap
is a type.Apologies if there's an existing issue for this.
The text was updated successfully, but these errors were encountered: