You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
by tux21b:
Attachments:
The text was updated successfully, but these errors were encountered: