]> Cypherpunks repositories - gostls13.git/commitdiff
template: fix handling of pointer inside interface
authorRuss Cox <rsc@golang.org>
Mon, 26 Apr 2010 17:01:13 +0000 (10:01 -0700)
committerRuss Cox <rsc@golang.org>
Mon, 26 Apr 2010 17:01:13 +0000 (10:01 -0700)
R=r
CC=golang-dev
https://golang.org/cl/982043

src/pkg/template/template.go
src/pkg/template/template_test.go

index 2bf21610b9fad13386b02056b580bb28678f9f1b..d15db7f8b8da5e92e229f18e25513c823c0ef2b3 100644 (file)
@@ -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) {
index 39c43e3e2df43345a8277fcd22269d8d7fd24690..a6267bfccf3e017e7715cebc28c64b3e1ee95b52 100644 (file)
@@ -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 {