summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2010-04-26 10:01:13 -0700
committerRuss Cox <rsc@golang.org>2010-04-26 10:01:13 -0700
commit68a702960410cfa81ff4950e478761da58b47204 (patch)
treef313dc08f300efadd6ffba69dc5bacb9a092416c
parentf31065a8707a5807d01c855ba867131a104d2a5d (diff)
downloadgolang-68a702960410cfa81ff4950e478761da58b47204.tar.gz
template: fix handling of pointer inside interface
R=r CC=golang-dev http://codereview.appspot.com/982043
-rw-r--r--src/pkg/template/template.go2
-rw-r--r--src/pkg/template/template_test.go7
2 files changed, 8 insertions, 1 deletions
diff --git a/src/pkg/template/template.go b/src/pkg/template/template.go
index 2bf21610b..d15db7f8b 100644
--- a/src/pkg/template/template.go
+++ b/src/pkg/template/template.go
@@ -596,7 +596,7 @@ func (st *state) findVar(s string) reflect.Value {
return nil
}
if intf, ok := data.(*reflect.InterfaceValue); ok {
- data = intf.Elem()
+ data = reflect.Indirect(intf.Elem())
}
switch typ := data.Type().(type) {
diff --git a/src/pkg/template/template_test.go b/src/pkg/template/template_test.go
index 39c43e3e2..a6267bfcc 100644
--- a/src/pkg/template/template_test.go
+++ b/src/pkg/template/template_test.go
@@ -48,6 +48,7 @@ type S struct {
stringmap map[string]string
bytes []byte
iface interface{}
+ ifaceptr interface{}
}
func (s *S) pointerMethod() string { return "ptrmethod!" }
@@ -385,6 +386,11 @@ var tests = []*Test{
out: "[1 2 3]",
},
+ &Test{
+ in: "{.section ifaceptr}{item} {value}{.end}",
+
+ out: "Item Value",
+ },
}
func TestAll(t *testing.T) {
@@ -423,6 +429,7 @@ func testAll(t *testing.T, parseFunc func(*Test) (*Template, os.Error)) {
s.stringmap["stringkey2"] = "stringresult"
s.bytes = []byte("hello")
s.iface = []int{1, 2, 3}
+ s.ifaceptr = &T{"Item", "Value"}
var buf bytes.Buffer
for _, test := range tests {