Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
encoding/gob: Check for GobEncoders/Decoders within structs? #6737
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.
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.