Skip to content
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

text/template: method discovery #3544

Closed
gopherbot opened this issue Apr 18, 2012 · 2 comments
Closed

text/template: method discovery #3544

gopherbot opened this issue Apr 18, 2012 · 2 comments
Assignees

Comments

@gopherbot
Copy link

@gopherbot gopherbot commented Apr 18, 2012

by tux21b:

The Go compiler automatically takes the address of a value V when a method is called
which is defined on a *V receiver. The "text/template" package should do the
same.

See the attached example for further details.

https://groups.google.com/d/msg/golang-nuts/eKSiPCAalMQ/O5JpDk8QpxUJ

Attachments:

  1. autodiscover.go (681 bytes)
@adg
Copy link
Contributor

@adg adg commented Apr 19, 2012

Comment 1:

Labels changed: added priority-soon, removed priority-triage.

Owner changed to @robpike.

Status changed to Accepted.

@robpike
Copy link
Contributor

@robpike robpike commented Apr 23, 2012

Comment 2:

Despite my "first blush" comment, this is not a bug. The template package handles this
correctly.
The example here is a textbook version of the 'settability' issue described near the end
of the "Laws of Reflection" blog post:
http://blog.golang.org/2011/09/laws-of-reflection.html.
When p2 is passed to the template library, the library receives a copy of p2, not p2
itself. It would be incorrect to take its address to discover the method.  Go in general
behaves the same way; if you say p2.X() the compiler can take the address of the local
variable p2, but that's not the same as passing p2 to a function, calling X, and
expecting the original p2 to be updated.
Working as intended, if subtly.

Status changed to WorkingAsIntended.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.