]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/json: rewrite interface{} to any
authorIan Lance Taylor <iant@golang.org>
Fri, 24 May 2024 03:50:25 +0000 (20:50 -0700)
committerGopher Robot <gobot@golang.org>
Wed, 24 Jul 2024 00:40:06 +0000 (00:40 +0000)
For #49884

Change-Id: I1623201c47c820a152773d2f43d0072a1466d3bf
Reviewed-on: https://go-review.googlesource.com/c/go/+/588118
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Commit-Queue: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@golang.org>

src/encoding/json/decode.go
src/encoding/json/encode.go
src/encoding/json/fuzz_test.go
src/encoding/json/stream.go

index f8205704e38b7ffa86b21816ae96ef4374b1184c..69a1013b8598fe95e4a841661a69f6acd6a2cae3 100644 (file)
@@ -53,8 +53,8 @@ import (
 //   - bool, for JSON booleans
 //   - float64, for JSON numbers
 //   - string, for JSON strings
-//   - []interface{}, for JSON arrays
-//   - map[string]interface{}, for JSON objects
+//   - []any, for JSON arrays
+//   - map[string]any, for JSON objects
 //   - nil for JSON null
 //
 // To unmarshal a JSON array into a slice, Unmarshal resets the slice length
@@ -466,7 +466,7 @@ func indirect(v reflect.Value, decodingNull bool) (Unmarshaler, encoding.TextUnm
                }
 
                // Prevent infinite loop if v is an interface pointing to its own address:
-               //     var v interface{}
+               //     var v any
                //     v = &v
                if v.Elem().Kind() == reflect.Interface && v.Elem().Elem() == v {
                        v = v.Elem()
@@ -1019,7 +1019,7 @@ func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool
 // in an empty interface. They are not strictly necessary,
 // but they avoid the weight of reflection in this common case.
 
-// valueInterface is like value but returns interface{}
+// valueInterface is like value but returns any.
 func (d *decodeState) valueInterface() (val any) {
        switch d.opcode {
        default:
@@ -1036,7 +1036,7 @@ func (d *decodeState) valueInterface() (val any) {
        return
 }
 
-// arrayInterface is like array but returns []interface{}.
+// arrayInterface is like array but returns []any.
 func (d *decodeState) arrayInterface() []any {
        var v = make([]any, 0)
        for {
@@ -1062,7 +1062,7 @@ func (d *decodeState) arrayInterface() []any {
        return v
 }
 
-// objectInterface is like object but returns map[string]interface{}.
+// objectInterface is like object but returns map[string]any.
 func (d *decodeState) objectInterface() map[string]any {
        m := make(map[string]any)
        for {
index 7bee1a6805f4dc2d836a9afe1f8cb28b0930b325..988de716124862593e56d20854e7655c610de82d 100644 (file)
@@ -819,7 +819,7 @@ func (se sliceEncoder) encode(e *encodeState, v reflect.Value, opts encOpts) {
                // Here we use a struct to memorize the pointer to the first element of the slice
                // and its length.
                ptr := struct {
-                       ptr interface{} // always an unsafe.Pointer, but avoids a dependency on package unsafe
+                       ptr any // always an unsafe.Pointer, but avoids a dependency on package unsafe
                        len int
                }{v.UnsafePointer(), v.Len()}
                if _, ok := e.ptrSeen[ptr]; ok {
index 778664c3e57e28059ff2793d123282f45b9d4cf5..f01960398a0e884175268f19ff3e45c7539bd5d1 100644 (file)
@@ -28,10 +28,10 @@ func FuzzUnmarshalJSON(f *testing.F) {
 }`))
 
        f.Fuzz(func(t *testing.T, b []byte) {
-               for _, typ := range []func() interface{}{
-                       func() interface{} { return new(interface{}) },
-                       func() interface{} { return new(map[string]interface{}) },
-                       func() interface{} { return new([]interface{}) },
+               for _, typ := range []func() any{
+                       func() any { return new(any) },
+                       func() any { return new(map[string]any) },
+                       func() any { return new([]any) },
                } {
                        i := typ()
                        if err := Unmarshal(b, i); err != nil {
index cb61ea721207e82c656aac17ff236d543caf8893..e2d9470bcc7fcaba1183b6aac565eadf3350a181 100644 (file)
@@ -32,8 +32,8 @@ func NewDecoder(r io.Reader) *Decoder {
        return &Decoder{r: r}
 }
 
-// UseNumber causes the Decoder to unmarshal a number into an interface{} as a
-// [Number] instead of as a float64.
+// UseNumber causes the Decoder to unmarshal a number into an
+// interface value as a [Number] instead of as a float64.
 func (dec *Decoder) UseNumber() { dec.d.useNumber = true }
 
 // DisallowUnknownFields causes the Decoder to return an error when the destination