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: Check for GobEncoders/Decoders within structs? #6737

Closed
CasualSuperman opened this issue Nov 8, 2013 · 8 comments
Closed

encoding/gob: Check for GobEncoders/Decoders within structs? #6737

CasualSuperman opened this issue Nov 8, 2013 · 8 comments

Comments

@CasualSuperman
Copy link

What steps will reproduce the problem?
1. Create a struct that includes a GobEncoder/GobDecoder as a field.
2. Use gob.Encode on an instance of that struct.
http://play.golang.org/p/_LyE3lvhpC

What is the expected output?
A successful encoding of the struct.

What do you see instead?
An error complaining about the inability to encode a function.

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

Which operating system are you using?
Linux

Which version are you using?  (run 'go version')
1.1.2

Please provide any additional information below.
I feel like checking fields for the GobEncode/Decode methods should be the default
behavior.
Otherwise, anyone who wants to use a type that requires the use of GobEncode/GobDecode
has to implement those methods in whatever struct contains it, just so it can call
GobEncode on the field, and copy the other fields verbatim. And then anyone who then
wants to include that struct as a field has to do so as well, and so on.
@CasualSuperman
Copy link
Author

Comment 1:

I actually just identified what I think is the problem, since upon further inspection I
found the gob code checks for this case.
I've changed my code locally, and the example runs.
In encoding/gob/type.go, function implementsInterface, the for loop contains a return,
when it should be a break. The next if statement after the loop (for this case) is
impossible to reach.

Attachments:

  1. patch.txt (378 bytes)

@CasualSuperman
Copy link
Author

Comment 2:

Submitted a code review for the patch. https://golang.org/cl/23470043

@robpike
Copy link
Contributor

robpike commented Nov 15, 2013

Comment 3:

Labels changed: added priority-soon, removed priority-triage.

Owner changed to @robpike.

Status changed to Accepted.

@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 4:

Labels changed: added go1.3maybe.

@CasualSuperman
Copy link
Author

Comment 5:

This appears to work on the playground with the update to 1.2, so this can probably be
marked as fixed.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 6:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 7:

Labels changed: added repo-main.

@robpike
Copy link
Contributor

robpike commented Dec 4, 2013

Comment 8:

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
@rsc rsc unassigned robpike Jun 22, 2022
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

4 participants