]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/json/v2: fix wrong type with cyclic marshal error in map[string]any
authorJoe Tsai <joetsai@digital-static.net>
Tue, 12 Aug 2025 08:45:44 +0000 (01:45 -0700)
committerJoseph Tsai <joetsai@digital-static.net>
Wed, 13 Aug 2025 22:47:11 +0000 (15:47 -0700)
The type reported in a ErrCycle is the wrong type due to a typo.
This discrepency was detected by setting optimizeCommon to false
and running the tests.

This only modifies code that is compiled in under goexperiment.jsonv2.

Change-Id: I68268f5c719d8b79a67424a35ed0647adf12288c
Reviewed-on: https://go-review.googlesource.com/c/go/+/695277
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Damien Neil <dneil@google.com>
src/encoding/json/v2/arshal_any.go
src/encoding/json/v2/arshal_test.go

index 3fb679d553e5dd6cfecd6537c51dcdc020b6502e..c2b09bd918fae23bf398d79ec772a83e6db10c8f 100644 (file)
@@ -104,7 +104,7 @@ func marshalObjectAny(enc *jsontext.Encoder, obj map[string]any, mo *jsonopts.St
        if xe.Tokens.Depth() > startDetectingCyclesAfter {
                v := reflect.ValueOf(obj)
                if err := visitPointer(&xe.SeenPointers, v); err != nil {
-                       return newMarshalErrorBefore(enc, anyType, err)
+                       return newMarshalErrorBefore(enc, mapStringAnyType, err)
                }
                defer leavePointer(&xe.SeenPointers, v)
        }
index 764ce690078a874c6c1745a13b66a5af91c08da7..5f5f072e25042993cedc289d8e0bc6c8a38abf25 100644 (file)
@@ -3278,7 +3278,7 @@ func TestMarshal(t *testing.T) {
                        return struct{ X any }{m}
                }(),
                want:    `{"X"` + strings.Repeat(`:{""`, startDetectingCyclesAfter),
-               wantErr: EM(internal.ErrCycle).withPos(`{"X":`+strings.Repeat(`{"":`, startDetectingCyclesAfter), "/X"+jsontext.Pointer(strings.Repeat("/", startDetectingCyclesAfter))).withType(0, T[any]()),
+               wantErr: EM(internal.ErrCycle).withPos(`{"X":`+strings.Repeat(`{"":`, startDetectingCyclesAfter), "/X"+jsontext.Pointer(strings.Repeat("/", startDetectingCyclesAfter))).withType(0, T[map[string]any]()),
        }, {
                name: jsontest.Name("Interfaces/Any/Slices/Nil"),
                in:   struct{ X any }{[]any(nil)},