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
runtime: misleading error when reflect type names clash #17283
Comments
Alternatively, to avoid unnecessarily long lines a common prefix could be stripped:
|
I could come up with a patch for this, but first I want input on whether this makes sense at all. @quentinmit I assume that's what |
It's fine to send a patch for this (see https://golang.org/doc/contribute.html). Thanks. Note that the compiler is supposed to already do this. See the code in |
@ianlancetaylor thanks for the pointer. I've been playing around with debug prints. I assume you were referring to:
But that code will not run when my error is being prepared - when the two The way in which Do you have any pointers? Any idea why Thanks! |
@mvdan I'm sorry, I don't know the answers to your questions. You could try asking on golang-dev. |
@rsc you seem to have touched this code more than anyone else, any idea? I'd rather keep golang-dev as a last resource. |
@mvdan I'm happy to help you look into fixing this. |
Thanks @mdempsky! See #17283 (comment). If that's going in the wrong direction, how would you go about figuring this out without breaking the compiler at every step? |
Okay, familiarized myself a little with the code. So to summarize the problem, we're storing short package-name-qualified names for types like "foo.Bar", which we use in runtime.TypeAssertionError panics (and a couple other places). The problem is if we have two different package paths "x/foo" and "y/foo" that both use the package name "foo", the resulting error message is ambiguous. I don't think simply using package path for ambiguous package names will work for a couple reasons:
I suspect to really fix this, we would need to change TypeAssertionError to always use package path qualification, rather than package name qualification. |
Sounds fair. If the path up to the package name ends up being the same, perhaps |
That may work, but to reiterate: package name is not guaranteed to be a suffix of package path (or necessarily related at all). For example https://godoc.org/google.golang.org/api/plus/v1 has package path "google.golang.org/api/plus/v1" but package name "plus". |
Ah, right. Feel free to take over on the patch, as this seems non-trivial to fix. |
I'm having a second crack at this, and finally made a bit of progress. Will send a work-in-progress CL soon, and will ask for pointers from there. |
Change https://golang.org/cl/77210 mentions this issue: |
The Go compiler/runtime team discussed this and decided that we should change
to instead say
I.e., if the package names are the same (even if the type name is different), then we include the package path afterwards. Also that this isn't a blocking issue for 1.10. |
@mdempsky thank you - that seems like a good decision. I'll update my CL shortly before the 1.11 tree opens to implement this. |
I just realised that this issue is a dup of #11634. I wasn't able to find that previous issue when filing this one, and just stumbled across it now. Which should we keep? I'm leaning towards this newer one, as it has more discussion towards a solution, and it is already milestoned and assigned. |
Unfortunately, #11634 points out this problem is more general than we'd been considering here: we might need to distinguish complex types like I think let's close this in favor of the older issue. |
@mdempsky makes sense, thank you. I'm glad that at least we noticed early, before we sunk more time into a flawed solution and/or the wrong problem. |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?What operating system and processor architecture are you using (
go env
)?What did you do?
Run https://github.com/mvdan/reflect-names (play.golang.org does not do since I need multiple packages to trigger this).
What did you expect to see?
An error message that made me understand what was wrong.
What did you see instead?
The first solution that comes to mind is that if the two names clash, the full import path should be included. For example:
The text was updated successfully, but these errors were encountered: