-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: methods of the embedded struct field won't be promoted in two cases #69557
Comments
In my opinion it is not duplicate of the #14309. Specification states that the method names must be unique in the method set. I agree with that. Since the methods won't even be promoted in either my or the #14309 example, these programs are valid and should compile (if I omit assigning). I am talking here about adding note about cases when methods won't even be promoted and thus won't be part of the method set. |
See the spec wording on Selectors and the concept of depth. I think the first rule below addresses both of your concerns:
|
@adonovan I'm talking about the rules for adding methods of the embedded fields to the method set of the structure we're embedding into. It is not related to the selectors nor illegal selector expressions. |
The spec calls this process "promotion".
In fact it is. The method set of the outer struct type is the set of method selectors x.f that are legal, and the rules for promotion determine what is legal. For example, "x.f denotes the field or method at the shallowest depth in T where there is such an f. If there is not exactly one f with shallowest depth, the selector expression is illegal." |
@adonovan Amazing explanation, thanks. Unfortunately, it is not explained in that way in the specification. Perhaps the following should be included in the specification, it's very clear and useful (I cite you):
EDIT: Nvm, I found something similar:
|
What is the URL of the page with the issue?
https://go.dev/ref/spec#Struct_types
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 the promoted methods of the embedded struct field states:
However, promoted methods won't be included in 2 cases:
What did you see happen?
I created an example for each case. Note that only method names are the same, but the signatures are different.
First case:
Second case:
What did you expect to see?
I expect to see these two constrains for the promoted methods included in the specification.
The text was updated successfully, but these errors were encountered: