Skip to content

variables modified by later parameters are unreliably updated #30801

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
urandom2 opened this issue Mar 13, 2019 · 4 comments
Closed

variables modified by later parameters are unreliably updated #30801

urandom2 opened this issue Mar 13, 2019 · 4 comments

Comments

@urandom2
Copy link
Contributor

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
@winjeg
Copy link

winjeg commented Mar 13, 2019

The result for me on go 1.11.5 ran on my PC is as follows

[] 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

It seems like a bug on go playground.

GO ENV

set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\wenwen\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\wenwen\go
set GOPROXY=
set GORACE=
set GOROOT=D:\apps\goinst
set GOTMPDIR=
set GOTOOLDIR=D:\apps\goinst\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=D:\projects\go\github.com\winjeg\demo\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=C:\Users\wenwen\AppData\Local\Temp\go-build471180878=/tmp/go-build -gno-record-gcc-switches

@urandom2
Copy link
Contributor Author

I can reproduce this on my local system too, the play link is for ease of access.

@zigo101
Copy link

zigo101 commented Mar 13, 2019

@urandom2
Copy link
Contributor Author

unfortunate that behaviour changed between releases, but this seems like a pretty clear cut duplicate, thanks @go101

@golang golang locked and limited conversation to collaborators Mar 12, 2020
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

4 participants