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
Before filing a bug, please check whether it has been fixed since
the latest release: run "hg pull -u" and retry what you did to
reproduce the problem. Thanks.
What steps will reproduce the problem?
max@mahako:~/src/test$ cat test1.go
package main
import "os"
import "io"
import "template"
type Node struct {
Label string
Value1 *int
Value2 int
}
const tplStr = `Node {Label}:
Value1={.section Value1}{@}{.or}(unset){.end}
Value2={Value2}
`
var tpl = template.MustParse(tplStr, nil)
func (n *Node) Show(w io.Writer) (err os.Error) {
err = tpl.Execute(n, w)
return err
}
func main() {
var n Node
var i int = 33
n.Label = "michi"
n.Value1 = &i
n.Value2 = 44
n.Show(os.Stderr)
}
max@mahako:~/src/test$ 8g test1.go ; 8l -o test1 test1.8
max@mahako:~/src/test$ ./test1
Node michi:
Value1=0x35b9f8
Value2=44
What is the expected output?
max@mahako:~/src/test$ ./test1
Node michi:
Value1=33
Value2=44
What do you see instead?
max@mahako:~/src/test$ ./test1
Node michi:
Value1=0x35b9f8
Value2=44
Which compiler are you using (5g, 6g, 8g, gccgo)?
8g
Which operating system are you using?
Windows 7 (386) and Ubuntu Linux (386)
Which revision are you using? (hg identify)
867d37fb41a4+ release/release.2011-02-01.1
Please provide any additional information below.
Apparently template does not dereference pointers to ints and strings, it only follows
pointers to structs. I believe it should automatically deref others also.
Alternatively, there could be some syntax for dereferencing, for example {*@} ...?
The text was updated successfully, but these errors were encountered:
I think the auto dereference might be an interesting thing
for the default formatter to do, but it probably shouldn't for
user-installed formatters, which might be formatting pointers
to custom structs.
I was thinking along those lines but I'm not sure it's easy to do efficiently. The
default formatter does whatever Fprint does, which means that the dereferencing should
stop as soon as we reach a level that has a String method. That's a lot of reflection
for every value.
In short, it's easy but clumsy and expensive. Is it worth it?
by mhantsch:
The text was updated successfully, but these errors were encountered: