From 6db1acfcb64d486e947112239fafeef113a95890 Mon Sep 17 00:00:00 2001 From: Nao Yonashiro Date: Fri, 22 Apr 2022 00:35:58 +0900 Subject: [PATCH] fix: to care about the case of OpInterfacePtr fix #359 --- decode_test.go | 13 +++++++++++++ internal/encoder/opcode.go | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/decode_test.go b/decode_test.go index 577d1d5..1d9f47c 100644 --- a/decode_test.go +++ b/decode_test.go @@ -3918,3 +3918,16 @@ func TestIssue360(t *testing.T) { t.Errorf("unexpected result: %v", uints) } } + +func TestIssue359(t *testing.T) { + var a interface{} = 1 + var b interface{} = &a + var c interface{} = &b + v, err := json.Marshal(c) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + if string(v) != "1" { + t.Errorf("unexpected result: %v", string(v)) + } +} diff --git a/internal/encoder/opcode.go b/internal/encoder/opcode.go index b02ae35..05fc3ce 100644 --- a/internal/encoder/opcode.go +++ b/internal/encoder/opcode.go @@ -363,7 +363,7 @@ func copyOpcode(code *Opcode) *Opcode { func setTotalLengthToInterfaceOp(code *Opcode) { for c := code; !c.IsEnd(); { - if c.Op == OpInterface { + if c.Op == OpInterface || c.Op == OpInterfacePtr { c.Length = uint32(code.TotalLength()) } c = c.IterNext()