-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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: panic in reflect.Value.IsNil when encoding via pointer type alias #12562
Comments
CL https://golang.org/cl/15920 mentions this issue. |
The program in the report seems fundamentally wrong. It makes a Alias which is *Foo, but then once gob indirects it has a Foo with an Encode method, which is going to put the recursion back. If you 'type Alias Foo', as in http://play.golang.org/p/Lby39nmUE0, then everything works today. There may be cause for a clearer error here but that's all. |
Changing to unplanned. I may see if I can stop the panic from happening, but it's not a straightforward change, and since the program cannot work regardless, it's low priority. But leaving open in case inspiration strikes. |
The type interface documented is GobEncoder (and not GobEncode). From the problem description, you want to have the ability to use a type method accessing directly the gob encoder. The code suggested still crashes online and loops elsewhere because the encoder is redefined. Further *Foo is not a non-interface type as per documentation and the case is not detected. Below, is the code using GobEncoder/GobDecoder as per documentation which runs using the non-interface type.
|
I can recreate this with unary The The issue arises as A sample of code that fails to this is found here. The panic occurs on line Could this possibly be mitigated by modifying this statement to return |
Here is a program containing a type
Foo
that implementsgob.GobEncoder
in a silly way: by calling back intogob.Encoder.Encode
using a type alias in order to avoid recursing. (The real world use for this is to zero a problematic field and then gob-encode the rest.)It causes
gob.Encoder.Encode
to panic inreflect.Value.IsNil
:If I'm reading the documentation correctly, this program should work as expected (printing
Result: 17
). But even if it's not intended to work, it probably shouldn't cause a panic.Note that if you change it so that the alias looks like
type Alias Foo
, the program works whether you callEncode
withAlias(f)
or(*Alias)(&f)
.Go version:
The text was updated successfully, but these errors were encountered: