Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions encode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2134,3 +2134,17 @@ func TestImplementedMethodInterfaceType(t *testing.T) {
t.Fatalf("failed to encode implemented method interface type. expected:[%q] but got:[%q]", expected, got)
}
}

func TestEmptyStructInterface(t *testing.T) {
expected, err := stdjson.Marshal([]interface{}{struct{}{}})
if err != nil {
t.Fatal(err)
}
got, err := json.Marshal([]interface{}{struct{}{}})
if err != nil {
t.Fatal(err)
}
if !bytes.Equal(expected, got) {
t.Fatalf("failed to encode empty struct interface. expected:[%q] but got:[%q]", expected, got)
}
}
2 changes: 1 addition & 1 deletion internal/encoder/compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1506,7 +1506,6 @@ func compileStruct(ctx *compileContext, isPtr bool) (*Opcode, error) {

structEndCode := &Opcode{
Op: OpStructEnd,
Next: newEndOp(ctx),
Type: nil,
Indent: ctx.indent,
}
Expand All @@ -1531,6 +1530,7 @@ func compileStruct(ctx *compileContext, isPtr bool) (*Opcode, error) {
structEndCode.DisplayIdx = ctx.opcodeIndex
structEndCode.Idx = opcodeOffset(ctx.ptrIndex)
ctx.incIndex()
structEndCode.Next = newEndOp(ctx)

if prevField != nil && prevField.NextField == nil {
prevField.NextField = structEndCode
Expand Down