-
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
spec: embedded interfaces should include interface type literals #69481
Comments
CC @griesemer |
Thanks for raising the issue, but the spec is correct as is. As you cite yourself, the spec says:
The emphasis here is on the word may. It doesn't say that that's the only choice. In fact, the section on general interfaces allows the "embedding" of interface literals (and other types). The reason that the spec groups interfaces into 3 categories (basic interfaces, interfaces with embedding, general interfaces) is purely for didactic and historical reasons. Before Go 1.18, we just had basic interfaces and embedding of other interfaces. This is covered by the first two sub-sections on interface types. Then, with Go 1.18, interfaces were generalized and now represent type sets (rather than just method sets). In the spec, we could probably just describe general interfaces, but it would be a) harder to grasp the concept, and b) remove the connection to pre-Go 1.18 interfaces. It may be fine for a spec, but the current organization was deliberate to help bringing people along. Also, many Go programmers never need the most general interface definition. In short, "embedding" an interface literal is clearly permitted by the spec even though we do not traditionally call that an embedded interface. Closing. |
What is the URL of the page with the issue?
https://go.dev/ref/spec#Embedded_interfaces
What is your user agent?
Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36
Screenshot
No response
What did you do?
Specification for embedded interfaces states (I bolded myself):
It requires interface type name, but implementation currently accepts interface type literal as well.
The notes for GO 1.18 at the end of the specification also imply that it was only intended for interface type names, not interface type literals (I bolded myself):
What did you see happen?
It compiles successfully.
What did you expect to see?
I expect the implementation to remain as it is currently and just to update the specification.
That is, to change the following:
to:
or:
It doesn't need to be an interface type name, just interface type.
The text was updated successfully, but these errors were encountered: