1
0
mirror of https://github.com/golang/go synced 2024-11-25 04:07:55 -07:00

template: fix handling of pointer inside interface

R=r
CC=golang-dev
https://golang.org/cl/982043
This commit is contained in:
Russ Cox 2010-04-26 10:01:13 -07:00
parent 6f33f34bbc
commit 13bb28a40a
2 changed files with 8 additions and 1 deletions

View File

@ -596,7 +596,7 @@ func (st *state) findVar(s string) reflect.Value {
return nil return nil
} }
if intf, ok := data.(*reflect.InterfaceValue); ok { if intf, ok := data.(*reflect.InterfaceValue); ok {
data = intf.Elem() data = reflect.Indirect(intf.Elem())
} }
switch typ := data.Type().(type) { switch typ := data.Type().(type) {

View File

@ -48,6 +48,7 @@ type S struct {
stringmap map[string]string stringmap map[string]string
bytes []byte bytes []byte
iface interface{} iface interface{}
ifaceptr interface{}
} }
func (s *S) pointerMethod() string { return "ptrmethod!" } func (s *S) pointerMethod() string { return "ptrmethod!" }
@ -385,6 +386,11 @@ var tests = []*Test{
out: "[1 2 3]", out: "[1 2 3]",
}, },
&Test{
in: "{.section ifaceptr}{item} {value}{.end}",
out: "Item Value",
},
} }
func TestAll(t *testing.T) { 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.stringmap["stringkey2"] = "stringresult"
s.bytes = []byte("hello") s.bytes = []byte("hello")
s.iface = []int{1, 2, 3} s.iface = []int{1, 2, 3}
s.ifaceptr = &T{"Item", "Value"}
var buf bytes.Buffer var buf bytes.Buffer
for _, test := range tests { for _, test := range tests {