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: encode/decode to interface receiver fails #2938

Closed
gopherbot opened this issue Feb 9, 2012 · 3 comments
Closed

encoding/gob: encode/decode to interface receiver fails #2938

gopherbot opened this issue Feb 9, 2012 · 3 comments

Comments

@gopherbot
Copy link

by axel.schreiner:

This is using 'hg update release' on MacOS X Lion (hg update default and ./all.bash fail
early on).

Based on the package documentation I believe that data can be transfered to and from an
interface-typed variable. This does not seem to be the case.

The attached program can be run with the arguments ss is si ii to select a transfer from
and to a struct or an interface. Additionally, the argument reg will register the
structure with gob, but that does not change anything.

What steps will reproduce the problem?
1. compile the attached file
2. run it with options ss and is -- no error message.
3. run it with options si or ii -- error message from gob. 

What is the expected output?

No error message in case 3.

What do you see instead?

decoding error gob: wrong type received for local value main.Mer: Foo = struct { Bar
string; Beque string; }

Which compiler are you using (5g, 6g, 8g, gccgo)?

6g

Which operating system are you using?

MacOS X Lion

Which revision are you using?  (hg identify)

c1702f36df03 (release-branch.r60) release/release.r60.3

Attachments:

  1. demo.go (1446 bytes)
@rsc
Copy link
Contributor

rsc commented Feb 9, 2012

Comment 1:

Hi,
I think your test case is not doing what you think it is.
Specifically, if you pass an interface { Foo() } to a function
expecting an interface{}, it is the concrete value that gets
passed to the function, dressed as an interface{}.  It is not
the interface { Foo() } that gets passed inside the interface{}.
So when you say Encode(m), that's no different from Encode's
point of view than Encode(&Foo...).  If you were to try
Encode(&m), that would pass a *M (pointer to interface)
inside the interface{}, and gob would invoke its interface
encoding routines.  The same would happen if the interface
were inside a struct somewhere.  That should be enough
to make the ii case work, provided you do the registration too.
I don't believe the is or si cases are valid; at the least I don't
think they will do what you expect.  (They will do nothing,
or return an error.)  Gob requires that interfaces be matched
to interfaces during the round trip.
Russ

@rsc
Copy link
Contributor

rsc commented Feb 9, 2012

Comment 2:

Status changed to WaitingForReply.

@robpike
Copy link
Contributor

robpike commented Feb 10, 2012

Comment 3:

Status changed to Duplicate.

Merged into issue #2367.

@mikioh mikioh changed the title gob encode/decode to interface receiver fails encoding/gob: encode/decode to interface receiver fails Feb 26, 2015
@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
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