Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

text/template: empty templates with same name don't result in error #4603

Closed
moraes opened this issue Jan 1, 2013 · 3 comments
Closed

text/template: empty templates with same name don't result in error #4603

moraes opened this issue Jan 1, 2013 · 3 comments

Comments

@moraes
Copy link
Contributor

moraes commented Jan 1, 2013

When templates with the same name are parsed together, an error only occurs if all
templates are not empty:

http://play.golang.org/p/zCOU4ggrqe

Only the last test here pass on tip:

func TestRedefinition(t *testing.T) {
    _, err := New("root").Parse(`{{define "t"}}{{end}}{{define "t"}}{{end}}`, "", "", make(map[string]*Tree), nil)
    if err == nil {
        t.Errorf("expected error")
    }
    _, err = New("root").Parse(`{{define "t"}}a{{end}}{{define "t"}}{{end}}`, "", "", make(map[string]*Tree), nil)
    if err == nil {
        t.Errorf("expected error")
    }
    _, err = New("root").Parse(`{{define "t"}}{{end}}{{define "t"}}b{{end}}`, "", "", make(map[string]*Tree), nil)
    if err == nil {
        t.Errorf("expected error")
    }
    _, err = New("root").Parse(`{{define "t"}}a{{end}}{{define "t"}}b{{end}}`, "", "", make(map[string]*Tree), nil)
    if err == nil {
        t.Errorf("expected error")
    }
}

Is this expected?
@rsc
Copy link
Contributor

rsc commented Jan 7, 2013

Comment 1:

Sounds like a bug to me.

Labels changed: added priority-later, suggested, size-m, removed priority-triage.

Status changed to Accepted.

@adg
Copy link
Contributor

adg commented Jan 17, 2013

Comment 2:

Seems like a deliberate choice to me. See "godoc -src text/template associate", which
specifically allows redefinition of empty templates, and ignores the definition of empty
templates.
I am going to downgrade this issue to not-Go1.1. The behavior doesn't cause any problems.

Labels changed: added priority-someday, removed priority-later, go1.1, suggested.

Owner changed to @robpike.

@robpike
Copy link
Contributor

robpike commented Feb 13, 2013

Comment 3:

Andrew's analysis is correct. It's fine to have empty templates and fill them in later,
kind of in a declare-then-define-later pattern.

Status changed to WorkingAsIntended.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc unassigned robpike Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants