Skip to content

reflect: MapKeys on map returns the slice of all values from map, not keys #31617

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
workanator opened this issue Apr 22, 2019 · 3 comments
Closed

Comments

@workanator
Copy link

Hello, when I do reflect.ValueOf(m).MapKeys() where m is a map I get the slice of values from the map, not keys. The same issue with MapRange(), returned iterator returns values disregarding what do you call, Key() or Value(). Is that the correct behaviour or is that a bug?

You can try that behaviour here. I suppose the output should contain key1, two, sdkjf.

I'm using the latest version of Go 1.12.3, linux/amd64

My ENV is

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ME/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/devel/projects/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/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-build558732631=/tmp/go-build -gno-record-gcc-switches"
@julieqiu julieqiu changed the title MapKeys on map returns the slice of all values from map, not keys reflect: MapKeys on map returns the slice of all values from map, not keys Apr 22, 2019
@seebs
Copy link
Contributor

seebs commented Apr 22, 2019

try for idx, value := range slice instead of for value := range slice.

@dominikh
Copy link
Member

Closing, not a bug, just iterating over the slice incorrectly.

@workanator
Copy link
Author

Oh! So stupid mistake. They say do not work late at night. I do not listen...
Thank you guys for the help. And sorry for wasting your time.

@golang golang locked and limited conversation to collaborators Apr 22, 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