Skip to content

text/template: cannot traverse into unexported embedded fields to get exported fields anymore #13885

@rsc

Description

@rsc

After the reflect shuffling, text/template rejects .foo.Bar where foo is an unexported embedded field holding Bar. It probably should allow it (since reflect does too) but still reject plain .foo.

This is simplified from a real test failure.

$ cat x.go
package main

import (
    "html/template"
    "log"
    "os"
)

func main() {
    type foo struct {
        Bar int
    }
    type X struct {
        foo
    }
    t := template.Must(template.New("").Parse("{{.foo.Bar}}\n"))
    err := t.Execute(os.Stdout, new(X))
    if err != nil {
        log.Fatal(err)
    }
}
$ go1.5 run x.go
0
$ go run x.go
2016/01/08 15:55:14 template: :1:6: executing "" at <.foo.Bar>: foo is an unexported field of struct type *main.X
exit status 1
$ 

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions