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

spec: For each loop over slice of int64 gets automatically converted to int #20974

Closed
Tanz0rz opened this issue Jul 10, 2017 · 3 comments
Closed

Comments

@Tanz0rz
Copy link

Tanz0rz commented Jul 10, 2017

Please answer these questions before submitting your issue. Thanks!

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

1.8.3

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

GOARCH="amd64"
GOBIN="/home/logrhythm/go/bin"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/logrhythm/go"
GORACE=""
GOROOT="/bin/go"
GOTOOLDIR="/bin/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build020353338=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

What did you do?

for each automatically converts the type:

https://play.golang.com/p/VMm13-ykYS

What did you expect to see?

Type preserved. The Go compiler should not assume int64 is unnecessary.

What did you see instead?

Types were converted from int64 to int

@bradfitz
Copy link
Contributor

You have a bug in your program. See https://golang.org/ref/spec#For_range

For questions about Go, see https://golang.org/wiki/Questions.

@bradfitz
Copy link
Contributor

That is, the first value in a range expression over a slice is the index, not the value.

@Tanz0rz
Copy link
Author

Tanz0rz commented Jul 10, 2017

Hmm... That explains it. I still would argue that a for range loop with only one variable of interest should be the object itself and not the index of the list.

@mikioh mikioh changed the title For each loop over slice of int64 gets automatically converted to int spec: For each loop over slice of int64 gets automatically converted to int Jul 21, 2017
@golang golang locked and limited conversation to collaborators Jul 21, 2018
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

3 participants