From 88aa13e3006fb5de4fa8c800778b4c671853e399 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Thu, 7 Jul 2022 14:52:28 +0900 Subject: [PATCH] Fix comment for #379 --- internal/encoder/compiler.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/internal/encoder/compiler.go b/internal/encoder/compiler.go index 83eab572..64533f44 100644 --- a/internal/encoder/compiler.go +++ b/internal/encoder/compiler.go @@ -487,7 +487,9 @@ func (c *Compiler) listElemCode(typ *runtime.Type) (Code, error) { case typ.Kind() == reflect.Map: return c.ptrCode(runtime.PtrTo(typ)) default: - // Strictly not isPtr == true, but reflect.ValueOf().Index() is canAddr, so set isPtr == true. + // isPtr was originally used to indicate whether the type of top level is pointer. + // However, since the slice/array element is a specification that can get the pointer address, explicitly set isPtr to true. + // See here for related issues: https://github.com/goccy/go-json/issues/370 code, err := c.typeToCodeWithPtr(typ, true) if err != nil { return nil, err