Skip to content
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

fix: panic on embedded struct with recursive #483

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -2710,3 +2710,17 @@ func TestIssue441(t *testing.T) {
assertErr(t, err)
assertEq(t, "unexpected result", "{}", string(b))
}

func TestIssue459(t *testing.T) {
type A struct {
A *A `json:"a,omitempty"`
}

type B struct {
A
}

b, err := json.Marshal(B{})
assertErr(t, err)
assertEq(t, "unexpected result", "{}", string(b))
}
1 change: 1 addition & 0 deletions internal/encoder/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ func (c *StructCode) ToAnonymousOpcode(ctx *compileContext) Opcodes {
prevField = firstField
codes = codes.Add(fieldCodes...)
}
ctx.structTypeToCodes[uintptr(unsafe.Pointer(c.typ))] = codes
return codes
}

Expand Down