mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
all: gofmt -w -r 'interface{} -> any' src
And then revert the bootstrap cmd directories and certain testdata.
And adjust tests as needed.
Not reverting the changes in std that are bootstrapped,
because some of those changes would appear in API docs,
and we want to use any consistently.
Instead, rewrite 'any' to 'interface{}' in cmd/dist for those directories
when preparing the bootstrap copy.
A few files changed as a result of running gofmt -w
not because of interface{} -> any but because they
hadn't been updated for the new //go:build lines.
Fixes #49884.
Change-Id: Ie8045cba995f65bd79c694ec77a1b3d1fe01bb09
Reviewed-on: https://go-review.googlesource.com/c/go/+/368254
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
parent
083ef54624
commit
2580d0e08d
445 changed files with 1906 additions and 1875 deletions
|
|
@ -31,7 +31,7 @@ type U struct {
|
|||
}
|
||||
|
||||
type V struct {
|
||||
F1 interface{}
|
||||
F1 any
|
||||
F2 int32
|
||||
F3 Number
|
||||
F4 *VOuter
|
||||
|
|
@ -62,18 +62,18 @@ func (*SS) UnmarshalJSON(data []byte) error {
|
|||
|
||||
// ifaceNumAsFloat64/ifaceNumAsNumber are used to test unmarshaling with and
|
||||
// without UseNumber
|
||||
var ifaceNumAsFloat64 = map[string]interface{}{
|
||||
var ifaceNumAsFloat64 = map[string]any{
|
||||
"k1": float64(1),
|
||||
"k2": "s",
|
||||
"k3": []interface{}{float64(1), float64(2.0), float64(3e-3)},
|
||||
"k4": map[string]interface{}{"kk1": "s", "kk2": float64(2)},
|
||||
"k3": []any{float64(1), float64(2.0), float64(3e-3)},
|
||||
"k4": map[string]any{"kk1": "s", "kk2": float64(2)},
|
||||
}
|
||||
|
||||
var ifaceNumAsNumber = map[string]interface{}{
|
||||
var ifaceNumAsNumber = map[string]any{
|
||||
"k1": Number("1"),
|
||||
"k2": "s",
|
||||
"k3": []interface{}{Number("1"), Number("2.0"), Number("3e-3")},
|
||||
"k4": map[string]interface{}{"kk1": "s", "kk2": Number("2")},
|
||||
"k3": []any{Number("1"), Number("2.0"), Number("3e-3")},
|
||||
"k4": map[string]any{"kk1": "s", "kk2": Number("2")},
|
||||
}
|
||||
|
||||
type tx struct {
|
||||
|
|
@ -262,9 +262,9 @@ type Ambig struct {
|
|||
}
|
||||
|
||||
type XYZ struct {
|
||||
X interface{}
|
||||
Y interface{}
|
||||
Z interface{}
|
||||
X any
|
||||
Y any
|
||||
Z any
|
||||
}
|
||||
|
||||
type unexportedWithMethods struct{}
|
||||
|
|
@ -389,8 +389,8 @@ type mapStringToStringData struct {
|
|||
|
||||
type unmarshalTest struct {
|
||||
in string
|
||||
ptr interface{} // new(type)
|
||||
out interface{}
|
||||
ptr any // new(type)
|
||||
out any
|
||||
err error
|
||||
useNumber bool
|
||||
golden bool
|
||||
|
|
@ -414,13 +414,13 @@ var unmarshalTests = []unmarshalTest{
|
|||
{in: `-5`, ptr: new(int16), out: int16(-5)},
|
||||
{in: `2`, ptr: new(Number), out: Number("2"), useNumber: true},
|
||||
{in: `2`, ptr: new(Number), out: Number("2")},
|
||||
{in: `2`, ptr: new(interface{}), out: float64(2.0)},
|
||||
{in: `2`, ptr: new(interface{}), out: Number("2"), useNumber: true},
|
||||
{in: `2`, ptr: new(any), out: float64(2.0)},
|
||||
{in: `2`, ptr: new(any), out: Number("2"), useNumber: true},
|
||||
{in: `"a\u1234"`, ptr: new(string), out: "a\u1234"},
|
||||
{in: `"http:\/\/"`, ptr: new(string), out: "http://"},
|
||||
{in: `"g-clef: \uD834\uDD1E"`, ptr: new(string), out: "g-clef: \U0001D11E"},
|
||||
{in: `"invalid: \uD834x\uDD1E"`, ptr: new(string), out: "invalid: \uFFFDx\uFFFD"},
|
||||
{in: "null", ptr: new(interface{}), out: nil},
|
||||
{in: "null", ptr: new(any), out: nil},
|
||||
{in: `{"X": [1,2,3], "Y": 4}`, ptr: new(T), out: T{Y: 4}, err: &UnmarshalTypeError{"array", reflect.TypeOf(""), 7, "T", "X"}},
|
||||
{in: `{"X": 23}`, ptr: new(T), out: T{}, err: &UnmarshalTypeError{"number", reflect.TypeOf(""), 8, "T", "X"}}, {in: `{"x": 1}`, ptr: new(tx), out: tx{}},
|
||||
{in: `{"x": 1}`, ptr: new(tx), out: tx{}},
|
||||
|
|
@ -428,8 +428,8 @@ var unmarshalTests = []unmarshalTest{
|
|||
{in: `{"S": 23}`, ptr: new(W), out: W{}, err: &UnmarshalTypeError{"number", reflect.TypeOf(SS("")), 0, "W", "S"}},
|
||||
{in: `{"F1":1,"F2":2,"F3":3}`, ptr: new(V), out: V{F1: float64(1), F2: int32(2), F3: Number("3")}},
|
||||
{in: `{"F1":1,"F2":2,"F3":3}`, ptr: new(V), out: V{F1: Number("1"), F2: int32(2), F3: Number("3")}, useNumber: true},
|
||||
{in: `{"k1":1,"k2":"s","k3":[1,2.0,3e-3],"k4":{"kk1":"s","kk2":2}}`, ptr: new(interface{}), out: ifaceNumAsFloat64},
|
||||
{in: `{"k1":1,"k2":"s","k3":[1,2.0,3e-3],"k4":{"kk1":"s","kk2":2}}`, ptr: new(interface{}), out: ifaceNumAsNumber, useNumber: true},
|
||||
{in: `{"k1":1,"k2":"s","k3":[1,2.0,3e-3],"k4":{"kk1":"s","kk2":2}}`, ptr: new(any), out: ifaceNumAsFloat64},
|
||||
{in: `{"k1":1,"k2":"s","k3":[1,2.0,3e-3],"k4":{"kk1":"s","kk2":2}}`, ptr: new(any), out: ifaceNumAsNumber, useNumber: true},
|
||||
|
||||
// raw values with whitespace
|
||||
{in: "\n true ", ptr: new(bool), out: true},
|
||||
|
|
@ -472,10 +472,10 @@ var unmarshalTests = []unmarshalTest{
|
|||
{in: `[1, 2, 3]`, ptr: new(MustNotUnmarshalJSON), err: errors.New("MustNotUnmarshalJSON was used")},
|
||||
|
||||
// empty array to interface test
|
||||
{in: `[]`, ptr: new([]interface{}), out: []interface{}{}},
|
||||
{in: `null`, ptr: new([]interface{}), out: []interface{}(nil)},
|
||||
{in: `{"T":[]}`, ptr: new(map[string]interface{}), out: map[string]interface{}{"T": []interface{}{}}},
|
||||
{in: `{"T":null}`, ptr: new(map[string]interface{}), out: map[string]interface{}{"T": interface{}(nil)}},
|
||||
{in: `[]`, ptr: new([]any), out: []any{}},
|
||||
{in: `null`, ptr: new([]any), out: []any(nil)},
|
||||
{in: `{"T":[]}`, ptr: new(map[string]any), out: map[string]any{"T": []any{}}},
|
||||
{in: `{"T":null}`, ptr: new(map[string]any), out: map[string]any{"T": any(nil)}},
|
||||
|
||||
// composite tests
|
||||
{in: allValueIndent, ptr: new(All), out: allValue},
|
||||
|
|
@ -1176,7 +1176,7 @@ func TestUnmarshal(t *testing.T) {
|
|||
|
||||
func TestUnmarshalMarshal(t *testing.T) {
|
||||
initBig()
|
||||
var v interface{}
|
||||
var v any
|
||||
if err := Unmarshal(jsonBig, &v); err != nil {
|
||||
t.Fatalf("Unmarshal: %v", err)
|
||||
}
|
||||
|
|
@ -1248,7 +1248,7 @@ type Xint struct {
|
|||
|
||||
func TestUnmarshalInterface(t *testing.T) {
|
||||
var xint Xint
|
||||
var i interface{} = &xint
|
||||
var i any = &xint
|
||||
if err := Unmarshal([]byte(`{"X":1}`), &i); err != nil {
|
||||
t.Fatalf("Unmarshal: %v", err)
|
||||
}
|
||||
|
|
@ -1382,8 +1382,8 @@ type All struct {
|
|||
PSmall *Small
|
||||
PPSmall **Small
|
||||
|
||||
Interface interface{}
|
||||
PInterface *interface{}
|
||||
Interface any
|
||||
PInterface *any
|
||||
|
||||
unexported int
|
||||
}
|
||||
|
|
@ -1717,9 +1717,9 @@ func intpp(x *int) **int {
|
|||
}
|
||||
|
||||
var interfaceSetTests = []struct {
|
||||
pre interface{}
|
||||
pre any
|
||||
json string
|
||||
post interface{}
|
||||
post any
|
||||
}{
|
||||
{"foo", `"bar"`, "bar"},
|
||||
{"foo", `2`, 2.0},
|
||||
|
|
@ -1738,7 +1738,7 @@ var interfaceSetTests = []struct {
|
|||
|
||||
func TestInterfaceSet(t *testing.T) {
|
||||
for _, tt := range interfaceSetTests {
|
||||
b := struct{ X interface{} }{tt.pre}
|
||||
b := struct{ X any }{tt.pre}
|
||||
blob := `{"X":` + tt.json + `}`
|
||||
if err := Unmarshal([]byte(blob), &b); err != nil {
|
||||
t.Errorf("Unmarshal %#q: %v", blob, err)
|
||||
|
|
@ -1768,7 +1768,7 @@ type NullTest struct {
|
|||
PBool *bool
|
||||
Map map[string]string
|
||||
Slice []string
|
||||
Interface interface{}
|
||||
Interface any
|
||||
|
||||
PRaw *RawMessage
|
||||
PTime *time.Time
|
||||
|
|
@ -1989,7 +1989,7 @@ func TestSliceOfCustomByte(t *testing.T) {
|
|||
}
|
||||
|
||||
var decodeTypeErrorTests = []struct {
|
||||
dest interface{}
|
||||
dest any
|
||||
src string
|
||||
}{
|
||||
{new(string), `{"user": "name"}`}, // issue 4628.
|
||||
|
|
@ -2022,7 +2022,7 @@ var unmarshalSyntaxTests = []string{
|
|||
}
|
||||
|
||||
func TestUnmarshalSyntax(t *testing.T) {
|
||||
var x interface{}
|
||||
var x any
|
||||
for _, src := range unmarshalSyntaxTests {
|
||||
err := Unmarshal([]byte(src), &x)
|
||||
if _, ok := err.(*SyntaxError); !ok {
|
||||
|
|
@ -2035,8 +2035,8 @@ func TestUnmarshalSyntax(t *testing.T) {
|
|||
// Issue 4660
|
||||
type unexportedFields struct {
|
||||
Name string
|
||||
m map[string]interface{} `json:"-"`
|
||||
m2 map[string]interface{} `json:"abcd"`
|
||||
m map[string]any `json:"-"`
|
||||
m2 map[string]any `json:"abcd"`
|
||||
|
||||
s []int `json:"-"`
|
||||
}
|
||||
|
|
@ -2087,7 +2087,7 @@ func TestUnmarshalJSONLiteralError(t *testing.T) {
|
|||
// Issue 3717
|
||||
func TestSkipArrayObjects(t *testing.T) {
|
||||
json := `[{}]`
|
||||
var dest [0]interface{}
|
||||
var dest [0]any
|
||||
|
||||
err := Unmarshal([]byte(json), &dest)
|
||||
if err != nil {
|
||||
|
|
@ -2102,8 +2102,8 @@ func TestPrefilled(t *testing.T) {
|
|||
// Values here change, cannot reuse table across runs.
|
||||
var prefillTests = []struct {
|
||||
in string
|
||||
ptr interface{}
|
||||
out interface{}
|
||||
ptr any
|
||||
out any
|
||||
}{
|
||||
{
|
||||
in: `{"X": 1, "Y": 2}`,
|
||||
|
|
@ -2112,8 +2112,8 @@ func TestPrefilled(t *testing.T) {
|
|||
},
|
||||
{
|
||||
in: `{"X": 1, "Y": 2}`,
|
||||
ptr: &map[string]interface{}{"X": float32(3), "Y": int16(4), "Z": 1.5},
|
||||
out: &map[string]interface{}{"X": float64(1), "Y": float64(2), "Z": 1.5},
|
||||
ptr: &map[string]any{"X": float32(3), "Y": int16(4), "Z": 1.5},
|
||||
out: &map[string]any{"X": float64(1), "Y": float64(2), "Z": 1.5},
|
||||
},
|
||||
{
|
||||
in: `[2]`,
|
||||
|
|
@ -2150,7 +2150,7 @@ func TestPrefilled(t *testing.T) {
|
|||
}
|
||||
|
||||
var invalidUnmarshalTests = []struct {
|
||||
v interface{}
|
||||
v any
|
||||
want string
|
||||
}{
|
||||
{nil, "json: Unmarshal(nil)"},
|
||||
|
|
@ -2173,7 +2173,7 @@ func TestInvalidUnmarshal(t *testing.T) {
|
|||
}
|
||||
|
||||
var invalidUnmarshalTextTests = []struct {
|
||||
v interface{}
|
||||
v any
|
||||
want string
|
||||
}{
|
||||
{nil, "json: Unmarshal(nil)"},
|
||||
|
|
@ -2205,7 +2205,7 @@ func TestInvalidStringOption(t *testing.T) {
|
|||
M map[string]string `json:",string"`
|
||||
S []string `json:",string"`
|
||||
A [1]string `json:",string"`
|
||||
I interface{} `json:",string"`
|
||||
I any `json:",string"`
|
||||
P *int `json:",string"`
|
||||
}{M: make(map[string]string), S: make([]string, 0), I: num, P: &num}
|
||||
|
||||
|
|
@ -2276,8 +2276,8 @@ func TestUnmarshalEmbeddedUnexported(t *testing.T) {
|
|||
|
||||
tests := []struct {
|
||||
in string
|
||||
ptr interface{}
|
||||
out interface{}
|
||||
ptr any
|
||||
out any
|
||||
err error
|
||||
}{{
|
||||
// Error since we cannot set S1.embed1, but still able to set S1.R.
|
||||
|
|
@ -2375,7 +2375,7 @@ func TestUnmarshalErrorAfterMultipleJSON(t *testing.T) {
|
|||
dec := NewDecoder(strings.NewReader(tt.in))
|
||||
var err error
|
||||
for {
|
||||
var v interface{}
|
||||
var v any
|
||||
if err = dec.Decode(&v); err != nil {
|
||||
break
|
||||
}
|
||||
|
|
@ -2403,7 +2403,7 @@ func TestUnmarshalPanic(t *testing.T) {
|
|||
// The decoder used to hang if decoding into an interface pointing to its own address.
|
||||
// See golang.org/issues/31740.
|
||||
func TestUnmarshalRecursivePointer(t *testing.T) {
|
||||
var v interface{}
|
||||
var v any
|
||||
v = &v
|
||||
data := []byte(`{"a": "b"}`)
|
||||
|
||||
|
|
@ -2517,36 +2517,36 @@ func TestUnmarshalMaxDepth(t *testing.T) {
|
|||
|
||||
targets := []struct {
|
||||
name string
|
||||
newValue func() interface{}
|
||||
newValue func() any
|
||||
}{
|
||||
{
|
||||
name: "unstructured",
|
||||
newValue: func() interface{} {
|
||||
var v interface{}
|
||||
newValue: func() any {
|
||||
var v any
|
||||
return &v
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "typed named field",
|
||||
newValue: func() interface{} {
|
||||
newValue: func() any {
|
||||
v := struct {
|
||||
A interface{} `json:"a"`
|
||||
A any `json:"a"`
|
||||
}{}
|
||||
return &v
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "typed missing field",
|
||||
newValue: func() interface{} {
|
||||
newValue: func() any {
|
||||
v := struct {
|
||||
B interface{} `json:"b"`
|
||||
B any `json:"b"`
|
||||
}{}
|
||||
return &v
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "custom unmarshaler",
|
||||
newValue: func() interface{} {
|
||||
newValue: func() any {
|
||||
v := unmarshaler{}
|
||||
return &v
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue