-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Closed
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Description
Go version
go version go1.21.5 linux/amd64
Output of go env in your module/workspace:
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
...What did you do?
Given the following template:
{{$y := .}}
{{ range $y = .sub }}
{{ . }}
{{ end }}
{{ $y }}
after parsing the template, and write the String repl of the parsed tree using:
for _, n := range tpl.Tree.Root.Nodes {
fmt.Print(n.String())
}
the result comes back as:
{{$y := .}}
{{range $y := .sub}}
{{.}}
{{end}}
{{$y}}
notice that the range changed from assignment to declare
https://github.com/golang/go/blob/702d609a31f02007b471c072b633fa4238554022/src/text/template/parse/node.go#L220C1-L221C1
writeto should test whether it is assigment or declare
What did you see happen?
the assignment part of the range changed to declaration.
What did you expect to see?
the semantic is preserved during parse -> String roundtrip.
Metadata
Metadata
Assignees
Labels
FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.