Possible template bug

67 views
Skip to first unread message

Christoph Hack

unread,
Apr 17, 2012, 7:21:06 PM4/17/12
to golan...@googlegroups.com
Hi gophers,

can someone explain the following snippet? As far as I remember the first commented line wasn't even valid Go code some time ago, and it still isn't if you use the template package. Why does the code behave differently here?


Regards,
Christoph

Andy Balholm

unread,
Apr 17, 2012, 7:29:59 PM4/17/12
to golan...@googlegroups.com
You can call methods that require a pointer receiver without explicitly taking the receiver's address. That's what's going on in the line you commented.

But when you pass the variable to a function, its address is not taken. If you pass &p2, it should work.

Christoph Hack

unread,
Apr 17, 2012, 7:39:26 PM4/17/12
to golan...@googlegroups.com


On Wednesday, April 18, 2012 1:29:59 AM UTC+2, AndyBalholm wrote:
You can call methods that require a pointer receiver without explicitly taking the receiver's address. That's what's going on in the line you commented.

As far as I remember, that wasn't always the case. I was pretty surprised that this behavior has changed.
 

But when you pass the variable to a function, its address is not taken. If you pass &p2, it should work.

It has nothing to do with passing p2 to a function. That works too. I think the issue is that the interpreter of the template package has a different behavior than the Go compiler itself. Imho that's a bug and the behavior should be consistent to avoid confusion.

Rob 'Commander' Pike

unread,
Apr 17, 2012, 7:56:49 PM4/17/12
to Christoph Hack, golan...@googlegroups.com
p2.Name has always worked in Go. You're right that the template
package is not providing the auto-address-of to discover the method,
although it tries to do so. I agree it looks like a bug at first
blush. Please file an issue.

-rob

Kyle Lemons

unread,
Apr 17, 2012, 8:06:56 PM4/17/12
to Christoph Hack, golan...@googlegroups.com
On Tue, Apr 17, 2012 at 4:39 PM, Christoph Hack <tux...@gmail.com> wrote:
On Wednesday, April 18, 2012 1:29:59 AM UTC+2, AndyBalholm wrote:
You can call methods that require a pointer receiver without explicitly taking the receiver's address. That's what's going on in the line you commented.

As far as I remember, that wasn't always the case. I was pretty surprised that this behavior has changed.

It's been the case for a long time... I stopped going back at 2010.

Christoph Hack

unread,
Apr 17, 2012, 8:15:00 PM4/17/12
to golan...@googlegroups.com, Christoph Hack
Hi Rob!

On Wednesday, April 18, 2012 1:56:49 AM UTC+2, r wrote:
Please file an issue.

Thanks for your reply. I have created issue #3544.


-christoph

Christoph Hack

unread,
Apr 17, 2012, 8:18:05 PM4/17/12
to golan...@googlegroups.com, Christoph Hack
On Wednesday, April 18, 2012 2:06:56 AM UTC+2, Kyle Lemons wrote:

It's been the case for a long time... I stopped going back at 2010.

Oh, looks like I am getting old :D
Reply all
Reply to author
Forward
0 new messages