diff --git a/encode_test.go b/encode_test.go index 1165f6a6..17fe65fd 100644 --- a/encode_test.go +++ b/encode_test.go @@ -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)) +} diff --git a/internal/encoder/code.go b/internal/encoder/code.go index 5b08faef..fec45a4b 100644 --- a/internal/encoder/code.go +++ b/internal/encoder/code.go @@ -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 }