Skip to content

Commit c01a989

Browse files
committed
Use any in place of interface{}
Earlier this evening I tried to run the Go [modernize](https://pkg.go.dev/golang.org/x/tools/gopls/internal/analysis/modernize) analyzer on OPA. That didn't go as planned: - golang/go#73661 - golang/go#73663 While we wait for that to be fixed, I figured an old-fashioned search-and-replace across the repo may work for at least the `interface{}` to `any` conversion. That should help make it easier to see the other fixes as applied by the modernize tool once it has had those issues resolved. Signed-off-by: Anders Eknert <[email protected]>
1 parent 13f212b commit c01a989

File tree

336 files changed

+2872
-2872
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

336 files changed

+2872
-2872
lines changed

ast/compare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ import (
3434
// Sets are considered equal if and only if the symmetric difference of a and b
3535
// is empty.
3636
// Other comparisons are consistent but not defined.
37-
func Compare(a, b interface{}) int {
37+
func Compare(a, b any) int {
3838
return v1.Compare(a, b)
3939
}

ast/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ type ErrorDetails = v1.ErrorDetails
4141
type Error = v1.Error
4242

4343
// NewError returns a new Error object.
44-
func NewError(code string, loc *Location, f string, a ...interface{}) *Error {
44+
func NewError(code string, loc *Location, f string, a ...any) *Error {
4545
return v1.NewError(code, loc, f, a...)
4646
}

ast/policy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func NewBody(exprs ...*Expr) Body {
211211
}
212212

213213
// NewExpr returns a new Expr object.
214-
func NewExpr(terms interface{}) *Expr {
214+
func NewExpr(terms any) *Expr {
215215
return v1.NewExpr(terms)
216216
}
217217

@@ -222,7 +222,7 @@ func NewBuiltinExpr(terms ...*Term) *Expr {
222222
}
223223

224224
// Copy returns a deep copy of the AST node x. If x is not an AST node, x is returned unmodified.
225-
func Copy(x interface{}) interface{} {
225+
func Copy(x any) any {
226226
return v1.Copy(x)
227227
}
228228

ast/pretty.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ import (
1313
// Pretty writes a pretty representation of the AST rooted at x to w.
1414
//
1515
// This is function is intended for debug purposes when inspecting ASTs.
16-
func Pretty(w io.Writer, x interface{}) {
16+
func Pretty(w io.Writer, x any) {
1717
v1.Pretty(w, x)
1818
}

ast/strings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ import (
99
)
1010

1111
// TypeName returns a human readable name for the AST element type.
12-
func TypeName(x interface{}) string {
12+
func TypeName(x any) string {
1313
return v1.TypeName(x)
1414
}

ast/term.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func NewLocation(text []byte, file string, row int, col int) *Location {
3030
type Value = v1.Value
3131

3232
// InterfaceToValue converts a native Go value x to a Value.
33-
func InterfaceToValue(x interface{}) (Value, error) {
33+
func InterfaceToValue(x any) (Value, error) {
3434
return v1.InterfaceToValue(x)
3535
}
3636

@@ -40,7 +40,7 @@ func ValueFromReader(r io.Reader) (Value, error) {
4040
}
4141

4242
// As converts v into a Go native type referred to by x.
43-
func As(v Value, x interface{}) error {
43+
func As(v Value, x any) error {
4444
return v1.As(v, x)
4545
}
4646

@@ -62,13 +62,13 @@ func IsUnknownValueErr(err error) bool {
6262
// ValueToInterface returns the Go representation of an AST value. The AST
6363
// value should not contain any values that require evaluation (e.g., vars,
6464
// comprehensions, etc.)
65-
func ValueToInterface(v Value, resolver Resolver) (interface{}, error) {
65+
func ValueToInterface(v Value, resolver Resolver) (any, error) {
6666
return v1.ValueToInterface(v, resolver)
6767
}
6868

6969
// JSON returns the JSON representation of v. The value must not contain any
7070
// refs or terms that require evaluation (e.g., vars, comprehensions, etc.)
71-
func JSON(v Value) (interface{}, error) {
71+
func JSON(v Value) (any, error) {
7272
return v1.JSON(v)
7373
}
7474

@@ -77,22 +77,22 @@ type JSONOpt = v1.JSONOpt
7777

7878
// JSONWithOpt returns the JSON representation of v. The value must not contain any
7979
// refs or terms that require evaluation (e.g., vars, comprehensions, etc.)
80-
func JSONWithOpt(v Value, opt JSONOpt) (interface{}, error) {
80+
func JSONWithOpt(v Value, opt JSONOpt) (any, error) {
8181
return v1.JSONWithOpt(v, opt)
8282
}
8383

8484
// MustJSON returns the JSON representation of v. The value must not contain any
8585
// refs or terms that require evaluation (e.g., vars, comprehensions, etc.) If
8686
// the conversion fails, this function will panic. This function is mostly for
8787
// test purposes.
88-
func MustJSON(v Value) interface{} {
88+
func MustJSON(v Value) any {
8989
return v1.MustJSON(v)
9090
}
9191

9292
// MustInterfaceToValue converts a native Go value x to a Value. If the
9393
// conversion fails, this function will panic. This function is mostly for test
9494
// purposes.
95-
func MustInterfaceToValue(x interface{}) Value {
95+
func MustInterfaceToValue(x any) Value {
9696
return v1.MustInterfaceToValue(x)
9797
}
9898

@@ -115,17 +115,17 @@ func IsComprehension(x Value) bool {
115115
}
116116

117117
// ContainsRefs returns true if the Value v contains refs.
118-
func ContainsRefs(v interface{}) bool {
118+
func ContainsRefs(v any) bool {
119119
return v1.ContainsRefs(v)
120120
}
121121

122122
// ContainsComprehensions returns true if the Value v contains comprehensions.
123-
func ContainsComprehensions(v interface{}) bool {
123+
func ContainsComprehensions(v any) bool {
124124
return v1.ContainsComprehensions(v)
125125
}
126126

127127
// ContainsClosures returns true if the Value v contains closures.
128-
func ContainsClosures(v interface{}) bool {
128+
func ContainsClosures(v any) bool {
129129
return v1.ContainsClosures(v)
130130
}
131131

@@ -256,7 +256,7 @@ func ObjectTerm(o ...[2]*Term) *Term {
256256
return v1.ObjectTerm(o...)
257257
}
258258

259-
func LazyObject(blob map[string]interface{}) Object {
259+
func LazyObject(blob map[string]any) Object {
260260
return v1.LazyObject(blob)
261261
}
262262

ast/transform.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ type Transformer = v1.Transformer
1616

1717
// Transform iterates the AST and calls the Transform function on the
1818
// Transformer t for x before recursing.
19-
func Transform(t Transformer, x interface{}) (interface{}, error) {
19+
func Transform(t Transformer, x any) (any, error) {
2020
return v1.Transform(t, x)
2121
}
2222

2323
// TransformRefs calls the function f on all references under x.
24-
func TransformRefs(x interface{}, f func(Ref) (Value, error)) (interface{}, error) {
24+
func TransformRefs(x any, f func(Ref) (Value, error)) (any, error) {
2525
return v1.TransformRefs(x, f)
2626
}
2727

2828
// TransformVars calls the function f on all vars under x.
29-
func TransformVars(x interface{}, f func(Var) (Value, error)) (interface{}, error) {
29+
func TransformVars(x any, f func(Var) (Value, error)) (any, error) {
3030
return v1.TransformVars(x, f)
3131
}
3232

3333
// TransformComprehensions calls the functio nf on all comprehensions under x.
34-
func TransformComprehensions(x interface{}, f func(interface{}) (Value, error)) (interface{}, error) {
34+
func TransformComprehensions(x any, f func(any) (Value, error)) (any, error) {
3535
return v1.TransformComprehensions(x, f)
3636
}
3737

@@ -41,6 +41,6 @@ type GenericTransformer = v1.GenericTransformer
4141

4242
// NewGenericTransformer returns a new GenericTransformer that will transform
4343
// AST nodes using the function f.
44-
func NewGenericTransformer(f func(x interface{}) (interface{}, error)) *GenericTransformer {
44+
func NewGenericTransformer(f func(x any) (any, error)) *GenericTransformer {
4545
return v1.NewGenericTransformer(f)
4646
}

ast/visit.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,68 +21,68 @@ type BeforeAndAfterVisitor = v1.BeforeAndAfterVisitor
2121
// Walk iterates the AST by calling the Visit function on the Visitor
2222
// v for x before recursing.
2323
// Deprecated: use GenericVisitor.Walk
24-
func Walk(v Visitor, x interface{}) {
24+
func Walk(v Visitor, x any) {
2525
v1.Walk(v, x)
2626
}
2727

2828
// WalkBeforeAndAfter iterates the AST by calling the Visit function on the
2929
// Visitor v for x before recursing.
3030
// Deprecated: use GenericVisitor.Walk
31-
func WalkBeforeAndAfter(v BeforeAndAfterVisitor, x interface{}) {
31+
func WalkBeforeAndAfter(v BeforeAndAfterVisitor, x any) {
3232
v1.WalkBeforeAndAfter(v, x)
3333
}
3434

3535
// WalkVars calls the function f on all vars under x. If the function f
3636
// returns true, AST nodes under the last node will not be visited.
37-
func WalkVars(x interface{}, f func(Var) bool) {
37+
func WalkVars(x any, f func(Var) bool) {
3838
v1.WalkVars(x, f)
3939
}
4040

4141
// WalkClosures calls the function f on all closures under x. If the function f
4242
// returns true, AST nodes under the last node will not be visited.
43-
func WalkClosures(x interface{}, f func(interface{}) bool) {
43+
func WalkClosures(x any, f func(any) bool) {
4444
v1.WalkClosures(x, f)
4545
}
4646

4747
// WalkRefs calls the function f on all references under x. If the function f
4848
// returns true, AST nodes under the last node will not be visited.
49-
func WalkRefs(x interface{}, f func(Ref) bool) {
49+
func WalkRefs(x any, f func(Ref) bool) {
5050
v1.WalkRefs(x, f)
5151
}
5252

5353
// WalkTerms calls the function f on all terms under x. If the function f
5454
// returns true, AST nodes under the last node will not be visited.
55-
func WalkTerms(x interface{}, f func(*Term) bool) {
55+
func WalkTerms(x any, f func(*Term) bool) {
5656
v1.WalkTerms(x, f)
5757
}
5858

5959
// WalkWiths calls the function f on all with modifiers under x. If the function f
6060
// returns true, AST nodes under the last node will not be visited.
61-
func WalkWiths(x interface{}, f func(*With) bool) {
61+
func WalkWiths(x any, f func(*With) bool) {
6262
v1.WalkWiths(x, f)
6363
}
6464

6565
// WalkExprs calls the function f on all expressions under x. If the function f
6666
// returns true, AST nodes under the last node will not be visited.
67-
func WalkExprs(x interface{}, f func(*Expr) bool) {
67+
func WalkExprs(x any, f func(*Expr) bool) {
6868
v1.WalkExprs(x, f)
6969
}
7070

7171
// WalkBodies calls the function f on all bodies under x. If the function f
7272
// returns true, AST nodes under the last node will not be visited.
73-
func WalkBodies(x interface{}, f func(Body) bool) {
73+
func WalkBodies(x any, f func(Body) bool) {
7474
v1.WalkBodies(x, f)
7575
}
7676

7777
// WalkRules calls the function f on all rules under x. If the function f
7878
// returns true, AST nodes under the last node will not be visited.
79-
func WalkRules(x interface{}, f func(*Rule) bool) {
79+
func WalkRules(x any, f func(*Rule) bool) {
8080
v1.WalkRules(x, f)
8181
}
8282

8383
// WalkNodes calls the function f on all nodes under x. If the function f
8484
// returns true, AST nodes under the last node will not be visited.
85-
func WalkNodes(x interface{}, f func(Node) bool) {
85+
func WalkNodes(x any, f func(Node) bool) {
8686
v1.WalkNodes(x, f)
8787
}
8888

@@ -93,7 +93,7 @@ type GenericVisitor = v1.GenericVisitor
9393

9494
// NewGenericVisitor returns a new GenericVisitor that will invoke the function
9595
// f on AST nodes.
96-
func NewGenericVisitor(f func(x interface{}) bool) *GenericVisitor {
96+
func NewGenericVisitor(f func(x any) bool) *GenericVisitor {
9797
return v1.NewGenericVisitor(f)
9898
}
9999

@@ -105,7 +105,7 @@ type BeforeAfterVisitor = v1.BeforeAfterVisitor
105105

106106
// NewBeforeAfterVisitor returns a new BeforeAndAfterVisitor that
107107
// will invoke the functions before and after AST nodes.
108-
func NewBeforeAfterVisitor(before func(x interface{}) bool, after func(x interface{})) *BeforeAfterVisitor {
108+
func NewBeforeAfterVisitor(before func(x any) bool, after func(x any)) *BeforeAfterVisitor {
109109
return v1.NewBeforeAfterVisitor(before, after)
110110
}
111111

bundle/store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func ReadBundleRevisionFromStore(ctx context.Context, store storage.Store, txn s
7070
// ReadBundleMetadataFromStore returns the metadata in the specified bundle.
7171
// If the bundle is not activated, this function will return
7272
// storage NotFound error.
73-
func ReadBundleMetadataFromStore(ctx context.Context, store storage.Store, txn storage.Transaction, name string) (map[string]interface{}, error) {
73+
func ReadBundleMetadataFromStore(ctx context.Context, store storage.Store, txn storage.Transaction, name string) (map[string]any, error) {
7474
return v1.ReadBundleMetadataFromStore(ctx, store, txn, name)
7575
}
7676

cmd/bench.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ func benchMain(args []string, params benchmarkCommandParams, w io.Writer, r benc
165165
return 1, errRender
166166
}
167167

168-
resultHandler := rego.GenerateJSON(func(*ast.Term, *rego.EvalContext) (interface{}, error) {
168+
resultHandler := rego.GenerateJSON(func(*ast.Term, *rego.EvalContext) (any, error) {
169169
// Do nothing with the result, as we are only interested in benchmarking evaluation —
170170
// not the potentially slow process of rendering the result.
171171
// Undefined / empty results will still be handled normally (fail the benchmark unless --fail
@@ -380,15 +380,15 @@ func benchE2E(ctx context.Context, args []string, params benchmarkCommandParams,
380380
}
381381

382382
// Wrap input in "input" attribute
383-
inp := make(map[string]interface{})
383+
inp := make(map[string]any)
384384

385385
if input != nil {
386386
if err = util.Unmarshal(input, &inp); err != nil {
387387
return err
388388
}
389389
}
390390

391-
body := map[string]interface{}{"input": inp}
391+
body := map[string]any{"input": inp}
392392

393393
var path string
394394
if params.partial {
@@ -426,7 +426,7 @@ func benchE2E(ctx context.Context, args []string, params benchmarkCommandParams,
426426
return nil
427427
}
428428

429-
func runE2E(params benchmarkCommandParams, url string, input map[string]interface{}) (testing.BenchmarkResult, error) {
429+
func runE2E(params benchmarkCommandParams, url string, input map[string]any) (testing.BenchmarkResult, error) {
430430
hist := metrics.New()
431431

432432
var benchErr error
@@ -482,7 +482,7 @@ func runE2E(params benchmarkCommandParams, url string, input map[string]interfac
482482
return br, benchErr
483483
}
484484

485-
func e2eQuery(params benchmarkCommandParams, url string, input map[string]interface{}) (types.MetricsV1, error) {
485+
func e2eQuery(params benchmarkCommandParams, url string, input map[string]any) (types.MetricsV1, error) {
486486

487487
reqBody, err := json.Marshal(input)
488488
if err != nil {
@@ -507,7 +507,7 @@ func e2eQuery(params benchmarkCommandParams, url string, input map[string]interf
507507
}
508508

509509
if resp.StatusCode != 200 {
510-
var e map[string]interface{}
510+
var e map[string]any
511511
if err = util.Unmarshal(body, &e); err != nil {
512512
return nil, err
513513
}
@@ -555,7 +555,7 @@ func e2eQuery(params benchmarkCommandParams, url string, input map[string]interf
555555

556556
i := *result.Result
557557

558-
peResult, ok := i.(map[string]interface{})
558+
peResult, ok := i.(map[string]any)
559559
if !ok {
560560
return nil, errors.New("invalid result for compile response")
561561
}
@@ -565,7 +565,7 @@ func e2eQuery(params benchmarkCommandParams, url string, input map[string]interf
565565
}
566566

567567
if val, ok := peResult["queries"]; ok {
568-
queries, ok := val.([]interface{})
568+
queries, ok := val.([]any)
569569
if !ok {
570570
return nil, errors.New("invalid result for output of partial evaluation")
571571
}
@@ -666,11 +666,11 @@ func prettyFormatFloat(x float64) string {
666666
return fmt.Sprintf(format, x)
667667
}
668668

669-
func reportMetrics(b *testing.B, m map[string]interface{}) {
669+
func reportMetrics(b *testing.B, m map[string]any) {
670670
// For each histogram add their values to the benchmark results.
671671
// Note: If there are many metrics this gets super verbose.
672672
for histName, metric := range m {
673-
histValues, ok := metric.(map[string]interface{})
673+
histValues, ok := metric.(map[string]any)
674674
if !ok {
675675
continue
676676
}

cmd/bench_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,7 @@ a contains 4 if {
12111211
RegoVersion: &tc.bundleRegoVersion,
12121212
FileRegoVersions: tc.bundleFileRegoVersions,
12131213
},
1214-
Data: map[string]interface{}{},
1214+
Data: map[string]any{},
12151215
}
12161216
for k, v := range tc.modules {
12171217
b.Modules = append(b.Modules, bundle.ModuleFile{
@@ -1550,9 +1550,9 @@ func testBundle() bundle.Bundle {
15501550

15511551
return bundle.Bundle{
15521552
Manifest: bundle.Manifest{},
1553-
Data: map[string]interface{}{
1554-
"a": map[string]interface{}{
1555-
"b": map[string]interface{}{
1553+
Data: map[string]any{
1554+
"a": map[string]any{
1555+
"b": map[string]any{
15561556
"c": 42,
15571557
},
15581558
},

0 commit comments

Comments
 (0)