Skip to content

variables modified by later parameters are unreliably updated #30801

Closed
@urandom2

Description

@urandom2

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

$ go version
go version go1.12 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
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/user/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/user/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/lib/go"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build021705053=/tmp/go-build -gno-record-gcc-switches"

What did you do?

var a []int
var b bool
var c complex64
var f float32
var i int
var m map[int]int
var r rune
var s string
var t struct{ i int }
var u uint

fmt.Println(a, b, c, f, i, m, r, s, t, u, func() string {
	fmt.Println(a, b, c, f, i, m, r, s, t, u, "first")
	a = []int{1}
	b = true
	c = complex(1, 1)
	f = 1
	i = 1
	m = map[int]int{1: 1}
	r = '1'
	s = "1"
	t = struct{ i int }{1}
	u = 1
	fmt.Println(a, b, c, f, i, m, r, s, t, u, "second")
	return "third"
}())

play

What did you expect to see?

either:

[] false (0+0i) 0 0 map[] 0  {0} 0 first
[1] true (1+1i) 1 1 map[1:1] 49 1 {1} 1 second
[] false (0+0i) 0 0 map[] 0  {0} 0 third

or

[] false (0+0i) 0 0 map[] 0  {0} 0 first
[1] true (1+1i) 1 1 map[1:1] 49 1 {1} 1 second
[1] true (1+1i) 1 1 map[1:1] 49 1 {1} 1 third

What did you see instead?

[] false (0+0i) 0 0 map[] 0  {0} 0 first
[1] true (1+1i) 1 1 map[1:1] 49 1 {1} 1 second
[1] false (0+0i) 1 1 map[] 49 1 {1} 1 third

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions