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: better error message for scoped type error #15575
Comments
/cc @mdempsky |
It's not a common mistake: local types are rare, and local types named like outer types are even more rare, so I'd say there's no urgency on this. That said, if we just say something like "type T (defined in F)" we could provide a very accurate message. Shouldn't be hard to do. It's a bit of a balance between precision of error and overly verbose error message. |
It's also possible (albeit increasingly unlikely) for multiple type Ts to be declared within a single function, so there may be cases where we want to disambiguate identically named types by line number instead: https://play.golang.org/p/zs6_-3awLP |
@mdempsky Indeed. It probably would be better to just report the line number (or file:line info). Needs a bit of experimentation for a pleasant result. |
CL https://golang.org/cl/42750 mentions this issue. |
CL 42750 adds support for line number disambiguation when using two different-but-identical-looking named types, but there are also cases where we have different-but-identical-looking anonymous types. For example:
currently emits:
And in general, there might be arbitrarily many different named types within the source and destination types (e.g., maps and structs) Are we happy to only special case named types? Or any ideas how to explain to the user why "map[K]V" and "map[K]V" might be different types? |
I didn't think about that. It seems less likely to occur, but I don't like the inconsistency. Happy to abandon the CL. |
Not urgent. Moving to 1.10. |
go version
)?go version go1.6.2 darwin/amd64
go env
)?https://play.golang.org/p/pJBsVvubBw
An error message that was clear
Spent over an hour figuring out why
type a
was not takingtype a
I think there should be a better error message for this case, as debugging it was super hard.
The text was updated successfully, but these errors were encountered: