Given that I have an empty "test" template:
tpl, err := template.New("main").Parse(`
{{template "test" .}}
{{define "test"}}{{end}}
`)
this works:
tpl, err = tpl.New("test").Parse(`This is a test`)
// no error
and this fails:
test, err := template.New("test").Parse(`This is a test`)
tpl, err = tpl.AddParseTree("test", test.Tree)
// error
I think the AddParseTree conditional should be changed to:
if t.common != nil
if old := t.tmpl[name]; old != nil && !parse.IsEmptyTree(old.Root) {
return nil, fmt.Errorf("template: redefinition of template %q", name)
}
}
This would make the behavior of AddParseTree consistent with Parse.