Merge pull request #291 from orisano/fix/#290

Fix encoding of nil value about interface type that has method
This commit is contained in:
Masaaki Goshima 2021-09-27 20:30:39 +09:00 committed by GitHub
commit 9df46fc918
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 35 additions and 5 deletions

View File

@ -2148,3 +2148,23 @@ func TestEmptyStructInterface(t *testing.T) {
t.Fatalf("failed to encode empty struct interface. expected:[%q] but got:[%q]", expected, got)
}
}
func TestIssue290(t *testing.T) {
type Issue290 interface {
A()
}
var a struct {
A Issue290
}
expected, err := stdjson.Marshal(a)
if err != nil {
t.Fatal(err)
}
got, err := json.Marshal(a)
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(expected, got) {
t.Fatalf("failed to encode non empty interface. expected = %q but got %q", expected, got)
}
}

View File

@ -194,7 +194,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
if code.Flags&encoder.NonEmptyInterfaceFlags != 0 {
iface := (*nonEmptyInterface)(up)
ifacePtr = iface.ptr
typ = iface.itab.typ
if iface.itab != nil {
typ = iface.itab.typ
}
} else {
iface := (*emptyInterface)(up)
ifacePtr = iface.ptr

View File

@ -194,7 +194,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
if code.Flags&encoder.NonEmptyInterfaceFlags != 0 {
iface := (*nonEmptyInterface)(up)
ifacePtr = iface.ptr
typ = iface.itab.typ
if iface.itab != nil {
typ = iface.itab.typ
}
} else {
iface := (*emptyInterface)(up)
ifacePtr = iface.ptr

View File

@ -194,7 +194,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
if code.Flags&encoder.NonEmptyInterfaceFlags != 0 {
iface := (*nonEmptyInterface)(up)
ifacePtr = iface.ptr
typ = iface.itab.typ
if iface.itab != nil {
typ = iface.itab.typ
}
} else {
iface := (*emptyInterface)(up)
ifacePtr = iface.ptr

View File

@ -194,7 +194,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
if code.Flags&encoder.NonEmptyInterfaceFlags != 0 {
iface := (*nonEmptyInterface)(up)
ifacePtr = iface.ptr
typ = iface.itab.typ
if iface.itab != nil {
typ = iface.itab.typ
}
} else {
iface := (*emptyInterface)(up)
ifacePtr = iface.ptr

View File

@ -194,7 +194,9 @@ func Run(ctx *encoder.RuntimeContext, b []byte, codeSet *encoder.OpcodeSet) ([]b
if code.Flags&encoder.NonEmptyInterfaceFlags != 0 {
iface := (*nonEmptyInterface)(up)
ifacePtr = iface.ptr
typ = iface.itab.typ
if iface.itab != nil {
typ = iface.itab.typ
}
} else {
iface := (*emptyInterface)(up)
ifacePtr = iface.ptr