You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Before filing a bug, please check whether it has been fixed since the
I think it should already been fixed long ago. But I cannot find the issue tracking
status.
Run "go version" and compare against
go version go1
Thanks.
What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
1 Run the following program:
package main
import (
"bytes"
"encoding/gob"
"fmt"
)
type P interface {
Q()
}
type A struct {
J P
}
type B struct {
P int
}
func (b *B) Q() {
}
func main() {
b := B{2}
c := A{&b}
gob.Register(A{})
gob.Register(B{})
var buffer bytes.Buffer
en := gob.NewEncoder(&buffer)
if err := en.Encode(&c); err != nil {
panic(err.Error())
}
buff := bytes.NewBuffer(buffer.Bytes())
de := gob.NewDecoder(buff)
if err := de.Decode(&c); err != nil {
fmt.Println(err.Error())
} else {
fmt.Println(c)
}
}
What is the expected output?
Should throw no errors
What do you see instead?
A runtime error saying gob: cannot assign value of type main.B to main.P
Which compiler are you using (5g, 6g, 8g, gccgo)?
6g
Which operating system are you using?
Mac OSX 10.7.4
Which version are you using? (run 'go version')
go version go1
Please provide any additional information below.
Related discussion can be found
https://groups.google.com/d/topic/golang-nuts/nl3GMEoT1KU/discussionhttps://groups.google.com/d/topic/golang-nuts/2EFErFqpNwI/discussion
The text was updated successfully, but these errors were encountered:
You need to register the type *B, as that is what implements the interface.
So register &B{} or (*B)(nil).
You don't need to register A at all, since it is not used in interfaces.
http://play.golang.org/p/FO3hNdzRkL
by AwakenRz:
The text was updated successfully, but these errors were encountered: