-
Notifications
You must be signed in to change notification settings - Fork 17.6k
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: surprising behavior for doubly declared methods #66285
Comments
I agree that the error should be present even when io.Reader is imported from a newer package. If we don't understand why this is happening, then maybe it is worth understanding better, just in case it is symptomatic of some larger bug in the way we think about or handle versions. That said, if we do understand it and it's just annoying to fix, I think it would be fine to take the check out entirely. The only reason for the check would be to help users keep their code compatible with Go 1.13, but Go 1.13 has been unsupported for many years now, so that's not a reason anymore. |
We do understand where it's coming from and the fix is trivial (actually simplifies the code). Thanks for the comment. |
Change https://go.dev/cl/571058 mentions this issue: |
Before Go 1.13, it was an error for a method to appear more than once (via embedding) in an interface. For instance, this code produced an error ("duplicate method Read"). With 1.14, such code was permitted.
Similarly, this code also produces the same error under 1.13 as one would expect:
However, this code does not:
The reason is that here the method
Read
both times is imported (throughio.Reader
): because theio
package is "correct", the importedRead
method is "exempt" from the 1.13 version check. This seems odd: even thoughio
is valid, the actual embedding ofRead
happens in the current package (or file) and thus the 1.13 rules should apply irrespective of where the method came from.A method's origin package should not matter for the version test, only the (file) version of the source where the embedding happens.
The text was updated successfully, but these errors were encountered: