-
Notifications
You must be signed in to change notification settings - Fork 18k
spec: clarify intended behaviour of method values using promoted methods #6475
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
Labels
Documentation
Issues describing a change to documentation.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Comments
This is definitely what I would expect to happen, and IMO the compiler is doing the right thing. Perhaps a small change to the spec is necessary, to mention the possibility of dereferencing x in x.M. Owner changed to @griesemer. Status changed to Accepted. |
The behaviour of sFn seems consistent with the behaviour of iFn logically, I just wasn't sure if it was expected based on the wording of the spec. I was checking through the spec to see how the term "receiver" was used because of a topic I posted to the mailing list, and happened upon this. It already says that x in x.M will be dereferenced to match the receiver of the function. Dereferencing just doesn't normally mean traversing anonymous fields. I suppose the current behaviour could be justified using the "x.f is shorthand for (*x.A).f" rule, but nowhere else is the literal expansion of this "shorthand" semantically significant, that I can think of. If this is the basis for the current behaviour, then it bears mentioning along with auto-reference/dereference, especially since auto-dereference is just a special case of it. I didn't think it was worth mentioning, but the other behaviour (observing the change to *t rather than not) is observed when an interface is involved: http://play.golang.org/p/993ZmY8324 But I was fairly certain this was expected based on both the language spec and how interfaces normally behave as an opaque barrier between static and dynamic dispatch of methods. |
The current behaviour is also consistent with the behaviour of defer: http://play.golang.org/p/oOrplS9704 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Documentation
Issues describing a change to documentation.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
The text was updated successfully, but these errors were encountered: