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

encoding/gob: decode map not eqaul encode value #20449

Closed
niubaoshu opened this issue May 22, 2017 · 4 comments
Closed

encoding/gob: decode map not eqaul encode value #20449

niubaoshu opened this issue May 22, 2017 · 4 comments

Comments

@niubaoshu
Copy link

Please answer these questions before submitting your issue. Thanks!

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

go version go1.8.1 windows/amd64

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

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\work\go
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\ADMINI~1\AppData\Local\Temp\go-build270790435=/tmp/go-build -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=1
set PKG_CONFIG=pkg-config
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2

What did you do?

If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.

https://play.golang.org/p/tDnbqdYOF2

What did you expect to see?

map[1:1]

What did you see instead?

this is a bug?

@odeke-em
Copy link
Member

Hello there @niubaoshu, is the bug you are reporting that mm map[int]string{"2": 2} when passed into dec.Decode(&mm) should have been entirely reset thus making it map[int]string{"1": 1} after decoding?

If so, my personal opinion is that that would be unexpected unless you have conflicting keys(in which that's implicit with a map for clashing keys); decoding values into a receiver is setting them in the receiver, and I don't see any promises of the proposed behavior in the encoding/gob docs
screen shot 2017-05-22 at 12 41 07 am

Let me ping some of the owners of the package @robpike @bradfitz, to give some input.

@niubaoshu
Copy link
Author

niubaoshu commented May 22, 2017

@odeke-em
Copy link
Member

Hmm, interesting. For comparison with other encoding/ packages, I've made https://play.golang.org/p/rQyWHKZhIS.

I'll defer to the decisions of the folks that I pinged earlier as I don't fully understand the correct behavior. Thank you for reporting the bug!

@robpike
Copy link
Contributor

robpike commented May 22, 2017

Working as intended. The decoder does not zero out the object before storing the values.

@robpike robpike closed this as completed May 22, 2017
@golang golang locked and limited conversation to collaborators May 22, 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

4 participants