Skip to content

text/template: key/value assignment is reversed within range loop #60801

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

Closed
jmooring opened this issue Jun 14, 2023 · 4 comments
Closed

text/template: key/value assignment is reversed within range loop #60801

jmooring opened this issue Jun 14, 2023 · 4 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@jmooring
Copy link

jmooring commented Jun 14, 2023

What version of Go are you using (go version)?

go version go1.20.5 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/jmooring/.cache/go-build"
GOENV="/home/jmooring/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/jmooring/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/jmooring/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/snap/go/current"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/snap/go/current/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.20.5"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build988921665=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
	"os"
	"text/template"
)

func main() {

	a := [1]string{"value"}

	t := `
		{{ $k := "" }}
		{{ $v := "" }}
		{{ range $k, $v = . }}
			{{ $k }} = {{ $v }}
		{{ end }}
	`

	tmpl, err := template.New("test").Parse(t)
	if err != nil {
		panic(err)
	}

	err = tmpl.Execute(os.Stdout, a)
	if err != nil {
		panic(err)
	}
}

What did you expect to see?

0 = value

What did you see instead?

value = 0

Other

This is a regression, introduced when fixing #56490.

@ianlancetaylor
Copy link
Contributor

ianlancetaylor commented Jun 14, 2023

@gopherbot Please open backport to 1.20.

This is a regression since previous versions.

@gopherbot
Copy link
Contributor

Backport issue(s) opened: #60802 (for 1.20).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/503575 mentions this issue: text/template: set variables correctly in range assignment

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/503576 mentions this issue: [release-branch.go1.20] text/template: set variables correctly in range assignment

@dmitshur dmitshur added the NeedsFix The path to resolution is known, but the work has not been done. label Jun 16, 2023
@dmitshur dmitshur added this to the Go1.21 milestone Jun 16, 2023
gopherbot pushed a commit that referenced this issue Jun 21, 2023
…ge assignment

I unintentionally flipped them in CL 446795.

For #56490
For #60801
Fixes #60802

Change-Id: I57586bec052e1b2cc61513870ce24dd6ce17e56b
Reviewed-on: https://go-review.googlesource.com/c/go/+/503576
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
@golang golang locked and limited conversation to collaborators Jun 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants