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
Describe the bug
If the codec attempts to unmarshal a struct into an interface field that the struct does not implement, the codec will panic rather than returning an error.
To Reproduce
This test case, when placed in the Codec folder, will fail.
type outerInterface interface {
ToInt() int
}
type outer struct {
Interface outerInterface `serialize:"true"`
}
type innerInterface struct{}
func (it *innerInterface) ToInt() int {
return 0
}
type innerNoInterface struct{}
// Ensure deserializing structs into the wrong interface errors gracefully
func TestUnmarshalInvalidInterface(t *testing.T) {
codec := NewDefault()
codec.RegisterType(&innerInterface{})
codec.RegisterType(&innerNoInterface{})
{
bytes := []byte{0, 0, 0, 0}
s := outer{}
if err := codec.Unmarshal(bytes, &s); err != nil {
t.Fatal(err)
}
}
{
bytes := []byte{0, 0, 0, 1}
s := outer{}
if err := codec.Unmarshal(bytes, &s); err == nil {
t.Fatalf("should have errored")
}
}
}
Expected behavior
The above test should pass.
Operating System
Universally applicable
The text was updated successfully, but these errors were encountered:
Describe the bug
If the codec attempts to unmarshal a struct into an interface field that the struct does not implement, the codec will panic rather than returning an error.
To Reproduce
This test case, when placed in the Codec folder, will fail.
Expected behavior
The above test should pass.
Operating System
Universally applicable
The text was updated successfully, but these errors were encountered: