diff --git a/cel/cel_example_test.go b/cel/cel_example_test.go index 873da434..f4c11b59 100644 --- a/cel/cel_example_test.go +++ b/cel/cel_example_test.go @@ -57,7 +57,7 @@ func Example() { } // Evaluate the program against some inputs. Note: the details return is not used. - out, _, err := prg.Eval(map[string]interface{}{ + out, _, err := prg.Eval(map[string]any{ // Native values are converted to CEL values under the covers. "i": "CEL", // Values may also be lazily supplied. @@ -107,7 +107,7 @@ func Example_globalOverload() { } // Evaluate the program against some inputs. Note: the details return is not used. - out, _, err := prg.Eval(map[string]interface{}{ + out, _, err := prg.Eval(map[string]any{ "i": "CEL", "you": func() ref.Val { return types.String("world") }, }) @@ -122,7 +122,7 @@ func Example_globalOverload() { func Example_statefulOverload() { // makeFetch produces a consistent function signature with a different function // implementation depending on the provided context. - makeFetch := func(ctx interface{}) cel.EnvOption { + makeFetch := func(ctx any) cel.EnvOption { fn := func(arg ref.Val) ref.Val { return types.NewErr("stateful context not bound") } diff --git a/cel/cel_test.go b/cel/cel_test.go index 93a684f9..013842f8 100644 --- a/cel/cel_test.go +++ b/cel/cel_test.go @@ -70,7 +70,7 @@ func Test_ExampleWithBuiltins(t *testing.T) { // If the Eval() call were provided with cel.EvalOptions(OptTrackState) the details response // (2nd return) would be non-nil. - out, _, err := prg.Eval(map[string]interface{}{ + out, _, err := prg.Eval(map[string]any{ "i": "CEL", "you": "world"}) if err != nil { @@ -101,7 +101,7 @@ func TestAbbrevsCompiled(t *testing.T) { t.Fatal(err) } out, _, err := prg.Eval( - map[string]interface{}{ + map[string]any{ "qualified.identifier.name.first": "Jim", }, ) @@ -130,7 +130,7 @@ func TestAbbrevsParsed(t *testing.T) { t.Fatal(err) } out, _, err := prg.Eval( - map[string]interface{}{ + map[string]any{ "qualified.identifier.name": map[string]string{ "first": "Jim", }, @@ -160,7 +160,7 @@ func TestAbbrevsDisambiguation(t *testing.T) { // of the 'test' argument. The fully qualified type name is used indicate that the protobuf // typed 'Expr' should be used rather than the abbreviatation for 'external.Expr'. out, err := interpret(t, env, `test ? dyn(Expr) : google.api.expr.v1alpha1.Expr{id: 1}`, - map[string]interface{}{ + map[string]any{ "test": true, "external.Expr": "string expr", }, @@ -172,7 +172,7 @@ func TestAbbrevsDisambiguation(t *testing.T) { t.Errorf("got %v, wanted 'string expr'", out) } out, err = interpret(t, env, `test ? dyn(Expr) : google.api.expr.v1alpha1.Expr{id: 1}`, - map[string]interface{}{ + map[string]any{ "test": false, "external.Expr": "wrong expr", }, @@ -214,7 +214,7 @@ func TestCustomEnv(t *testing.T) { }) t.Run("ok", func(t *testing.T) { - out, err := interpret(t, e, "a.b.c", map[string]interface{}{"a.b.c": true}) + out, err := interpret(t, e, "a.b.c", map[string]any{"a.b.c": true}) if err != nil { t.Fatal(err) } @@ -249,7 +249,7 @@ func TestHomogeneousAggregateLiterals(t *testing.T) { name string expr string iss string - vars map[string]interface{} + vars map[string]any out ref.Val }{ { @@ -282,13 +282,13 @@ func TestHomogeneousAggregateLiterals(t *testing.T) { { name: "ok_list", expr: `name in ['hello', 'world']`, - vars: map[string]interface{}{"name": "world"}, + vars: map[string]any{"name": "world"}, out: types.True, }, { name: "ok_map", expr: `name in {'hello': false, 'world': true}`, - vars: map[string]interface{}{"name": "world"}, + vars: map[string]any{"name": "world"}, out: types.True, }, } @@ -422,7 +422,7 @@ func TestCustomTypes(t *testing.T) { t.Fatalf("got %v, wanted type bool", ast.OutputType()) } prg, _ := e.Program(ast) - vars := map[string]interface{}{"expr": &exprpb.Expr{ + vars := map[string]any{"expr": &exprpb.Expr{ Id: 2, ExprKind: &exprpb.Expr_CallExpr{ CallExpr: &exprpb.Expr_Call{ @@ -492,7 +492,7 @@ func TestDynamicProto(t *testing.T) { t.Fatalf("proto.Unmarshal() failed: %v", err) } files := (&fds).GetFile() - fileCopy := make([]interface{}, len(files)) + fileCopy := make([]any, len(files)) for i := 0; i < len(files); i++ { fileCopy[i] = files[i] } @@ -550,7 +550,7 @@ func TestDynamicProto_Input(t *testing.T) { t.Fatalf("proto.Unmarshal() failed: %v", err) } files := (&fds).GetFile() - fileCopy := make([]interface{}, len(files)) + fileCopy := make([]any, len(files)) for i := 0; i < len(files); i++ { fileCopy[i] = files[i] } @@ -587,7 +587,7 @@ func TestDynamicProto_Input(t *testing.T) { if err != nil { t.Fatalf("env.Program() failed: %v", err) } - out, _, err := prg.Eval(map[string]interface{}{ + out, _, err := prg.Eval(map[string]any{ "mutant": wolverine, }) if err != nil { @@ -637,20 +637,20 @@ func TestGlobalVars(t *testing.T) { // Add a previous globals map to confirm the order of shadowing and a final empty global // map to show that globals are not clobbered. prg, err := e.Program(ast, - Globals(map[string]interface{}{ + Globals(map[string]any{ "default": "shadow me", }), - Globals(map[string]interface{}{ + Globals(map[string]any{ "default": "third", }), - Globals(map[string]interface{}{}), + Globals(map[string]any{}), ) if err != nil { t.Fatalf("e.Program() failed: %v", err) } t.Run("bad_attrs", func(t *testing.T) { - out, _, err := prg.Eval(map[string]interface{}{ + out, _, err := prg.Eval(map[string]any{ "attrs": []string{"one", "two"}, }) if err == nil { @@ -659,8 +659,8 @@ func TestGlobalVars(t *testing.T) { }) t.Run("global_default", func(t *testing.T) { - vars := map[string]interface{}{ - "attrs": map[string]interface{}{}, + vars := map[string]any{ + "attrs": map[string]any{}, } out, _, err := prg.Eval(vars) if err != nil { @@ -672,8 +672,8 @@ func TestGlobalVars(t *testing.T) { }) t.Run("attrs_alt", func(t *testing.T) { - vars := map[string]interface{}{ - "attrs": map[string]interface{}{"second": "yep"}} + vars := map[string]any{ + "attrs": map[string]any{"second": "yep"}} out, _, err := prg.Eval(vars) if err != nil { t.Fatalf("prg.Eval(vars) failed: %v", err) @@ -684,8 +684,8 @@ func TestGlobalVars(t *testing.T) { }) t.Run("local_default", func(t *testing.T) { - vars := map[string]interface{}{ - "attrs": map[string]interface{}{}, + vars := map[string]any{ + "attrs": map[string]any{}, "default": "fourth"} out, _, _ := prg.Eval(vars) if out.Equal(types.String("fourth")) != types.True { @@ -704,7 +704,7 @@ func TestMacroSubset(t *testing.T) { t.Fatalf("NewEnv() failed: %v", err) } out, err := interpret(t, env, `has(name.first)`, - map[string]interface{}{ + map[string]any{ "name": map[string]string{ "first": "Jim", }, @@ -833,7 +833,7 @@ func TestCustomExistsMacro(t *testing.T) { if err != nil { t.Fatalf("env.Program(ast) failed: %v", err) } - out, _, err := prg.Eval(map[string]interface{}{"attr": map[string]bool{"value": false}}) + out, _, err := prg.Eval(map[string]any{"attr": map[string]bool{"value": false}}) if err != nil { t.Errorf("prg.Eval() got %v, wanted non-error", err) } @@ -879,7 +879,7 @@ func TestEvalOptions(t *testing.T) { t.Fatalf("program creation error: %s\n", err) } out, details, err := prg.Eval( - map[string]interface{}{ + map[string]any{ "k": "key", "v": true}) if err != nil { @@ -929,7 +929,7 @@ func TestContextEval(t *testing.T) { for i := int64(0); i < 1000; i++ { items[i] = i } - out, _, err := prg.ContextEval(ctx, map[string]interface{}{"items": items}) + out, _, err := prg.ContextEval(ctx, map[string]any{"items": items}) if err != nil { t.Fatalf("prg.ContextEval() failed: %v", err) } @@ -940,7 +940,7 @@ func TestContextEval(t *testing.T) { evalCtx, cancel := context.WithTimeout(ctx, time.Microsecond) defer cancel() - out, _, err = prg.ContextEval(evalCtx, map[string]interface{}{"items": items}) + out, _, err = prg.ContextEval(evalCtx, map[string]any{"items": items}) if err == nil { t.Errorf("Got result %v, wanted timeout error", out) } @@ -971,7 +971,7 @@ func BenchmarkContextEval(b *testing.B) { items[i] = i } for i := 0; i < b.N; i++ { - out, _, err := prg.ContextEval(ctx, map[string]interface{}{"items": items}) + out, _, err := prg.ContextEval(ctx, map[string]any{"items": items}) if err != nil { b.Fatalf("prg.ContextEval() failed: %v", err) } @@ -1003,13 +1003,13 @@ func TestEvalRecover(t *testing.T) { if err != nil { t.Fatalf("e.Program(Ast) failed: %v", err) } - _, _, err = prgm.Eval(map[string]interface{}{}) + _, _, err = prgm.Eval(map[string]any{}) if err.Error() != "internal error: watch me recover" { t.Errorf("got '%v', wanted 'internal error: watch me recover'", err) } // Test the factory-based evaluation. prgm, _ = e.Program(pAst, EvalOptions(OptTrackState)) - _, _, err = prgm.Eval(map[string]interface{}{}) + _, _, err = prgm.Eval(map[string]any{}) if err.Error() != "internal error: watch me recover" { t.Errorf("got '%v', wanted 'internal error: watch me recover'", err) } @@ -1052,7 +1052,7 @@ func TestResidualAstComplex(t *testing.T) { Variable("request.auth.claims", MapType(StringType, StringType)), ) unkVars, _ := PartialVars( - map[string]interface{}{ + map[string]any{ "resource.name": "bucket/my-bucket/objects/private", "request.auth.claims": map[string]string{ "email_verified": "true", @@ -1096,7 +1096,7 @@ func BenchmarkEvalOptions(b *testing.B) { Variable("ar", MapType(StringType, StringType)), ) ast, _ := e.Compile("ai == 20 || ar['foo'] == 'bar'") - vars := map[string]interface{}{ + vars := map[string]any{ "ai": 2, "ar": map[string]string{ "foo": "bar", @@ -1402,20 +1402,20 @@ func TestEstimateCostAndRuntimeCost(t *testing.T) { decls []EnvOption hints map[string]int64 want checker.CostEstimate - in interface{} + in any }{ { name: "const", expr: `"Hello World!"`, want: zeroCost, - in: map[string]interface{}{}, + in: map[string]any{}, }, { name: "identity", expr: `input`, decls: []EnvOption{Variable("input", intList)}, want: checker.CostEstimate{Min: 1, Max: 1}, - in: map[string]interface{}{"input": []int{1, 2}}, + in: map[string]any{"input": []int{1, 2}}, }, { name: "str concat", @@ -1426,7 +1426,7 @@ func TestEstimateCostAndRuntimeCost(t *testing.T) { }, hints: map[string]int64{"str1": 10, "str2": 10}, want: checker.CostEstimate{Min: 2, Max: 6}, - in: map[string]interface{}{"str1": "val1111111", "str2": "val2222222"}, + in: map[string]any{"str1": "val1111111", "str2": "val2222222"}, }, } @@ -1463,7 +1463,7 @@ func TestEstimateCostAndRuntimeCost(t *testing.T) { } _, details, err := program.Eval(tc.in) if err != nil { - t.Fatalf(`Program.Eval(vars interface{}) failed to evaluate expression: %v`, err) + t.Fatalf(`Program.Eval(vars any) failed to evaluate expression: %v`, err) } actualCost := details.ActualCost() if actualCost == nil { @@ -1488,8 +1488,8 @@ func TestResidualAst_AttributeQualifiers(t *testing.T) { prg, _ := e.Program(ast, EvalOptions(OptTrackState, OptPartialEval), ) - vars, _ := PartialVars(map[string]interface{}{ - "x": map[string]interface{}{ + vars, _ := PartialVars(map[string]any{ + "x": map[string]any{ "zero": 0, "abc": 123, "string": "abc", @@ -1527,7 +1527,7 @@ func TestResidualAst_Modified(t *testing.T) { EvalOptions(OptTrackState, OptPartialEval), ) for _, x := range []int{123, 456} { - vars, _ := PartialVars(map[string]interface{}{ + vars, _ := PartialVars(map[string]any{ "x": x, }, AttributePattern("y")) out, det, err := prg.Eval(vars) @@ -1691,7 +1691,7 @@ func TestDefaultUTCTimeZone(t *testing.T) { && x.getMinutes('23:15') == 20 && x.getSeconds('23:15') == 6 && x.getMilliseconds('23:15') == 1`, - map[string]interface{}{ + map[string]any{ "x": time.Unix(7506, 1000000).Local(), }) if err != nil { @@ -1721,7 +1721,7 @@ func TestDefaultUTCTimeZoneExtension(t *testing.T) { && y.getMinutes() == 120 && y.getSeconds() == 7235 && y.getMilliseconds() == 7235000`, - map[string]interface{}{ + map[string]any{ "x": time.Unix(7506, 1000000).Local(), "y": time.Duration(7235) * time.Second, }, @@ -1750,7 +1750,7 @@ func TestDefaultUTCTimeZoneError(t *testing.T) { || x.getMinutes('Am/Ph') == 5 || x.getSeconds('Am/Ph') == 6 || x.getMilliseconds('Am/Ph') == 1 - `, map[string]interface{}{ + `, map[string]any{ "x": time.Unix(7506, 1000000).Local(), }, ) @@ -1815,7 +1815,7 @@ func TestDynamicDispatch(t *testing.T) { && dyn([1.0, 2.0]).first() == 1.0 && dyn(["hello", "world"]).first() == "hello" && dyn([["hello"], ["world", "!"]]).first().first() == "hello" - `, map[string]interface{}{}, + `, map[string]any{}, ) if err != nil { t.Fatalf("prg.Eval() failed: %v", err) @@ -1838,12 +1838,12 @@ func TestOptionalValues(t *testing.T) { } tests := []struct { expr string - in map[string]interface{} - out interface{} + in map[string]any + out any }{ { expr: `x.or(y).orValue(z)`, - in: map[string]interface{}{ + in: map[string]any{ "x": types.OptionalNone, "y": types.OptionalNone, "z": 42, @@ -1852,7 +1852,7 @@ func TestOptionalValues(t *testing.T) { }, { expr: `optional.ofNonZeroValue(z).or(optional.of(10)).value() == 42`, - in: map[string]interface{}{ + in: map[string]any{ "z": 42, }, out: true, @@ -1860,7 +1860,7 @@ func TestOptionalValues(t *testing.T) { { // In the future this can be expressed as: m.?x expr: `(has(m.x) ? optional.of(m.x) : optional.none()).hasValue()`, - in: map[string]interface{}{ + in: map[string]any{ "m": map[string]map[string]string{}, }, out: false, @@ -1868,7 +1868,7 @@ func TestOptionalValues(t *testing.T) { { // return the value of m.c['dashed-index'], no magic in the optional.of() call. expr: `optional.ofNonZeroValue('').or(optional.of(m.c['dashed-index'])).orValue('default value')`, - in: map[string]interface{}{ + in: map[string]any{ "m": map[string]map[string]string{ "c": map[string]string{ "dashed-index": "goodbye", @@ -1880,7 +1880,7 @@ func TestOptionalValues(t *testing.T) { { // ensure an error is propagated to the result. expr: `optional.ofNonZeroValue(m.a.z).orValue(m.c['dashed-index'])`, - in: map[string]interface{}{ + in: map[string]any{ "m": map[string]map[string]string{ "c": map[string]string{ "dashed-index": "goodbye", @@ -1931,7 +1931,7 @@ func BenchmarkOptionalValues(b *testing.B) { if err != nil { b.Errorf("env.Program() failed: %v", err) } - input := map[string]interface{}{ + input := map[string]any{ "x": types.OptionalNone, "y": types.OptionalNone, "z": 42, @@ -2034,7 +2034,7 @@ func compileOrError(t testing.TB, env *Env, expr string) (Program, error) { return prg, nil } -func interpret(t testing.TB, env *Env, expr string, vars interface{}) (ref.Val, error) { +func interpret(t testing.TB, env *Env, expr string, vars any) (ref.Val, error) { t.Helper() prg, err := compileOrError(t, env, expr) if err != nil { diff --git a/cel/decls_test.go b/cel/decls_test.go index 0547b42a..60dad8be 100644 --- a/cel/decls_test.go +++ b/cel/decls_test.go @@ -37,7 +37,7 @@ import ( var dispatchTests = []struct { expr string - out interface{} + out any }{ { expr: "max(-1)", @@ -200,7 +200,7 @@ func TestFunctionMergeDeclarationAndDefinition(t *testing.T) { if err != nil { t.Fatalf("env.Program() failed: %v", err) } - out, _, err := prg.Eval(map[string]interface{}{"x": true}) + out, _, err := prg.Eval(map[string]any{"x": true}) if err != nil { t.Fatalf("prg.Eval(x: true) errored: %v", err) } @@ -264,7 +264,7 @@ func TestSingletonUnaryBinding(t *testing.T) { if err != nil { t.Fatalf("Program() failed: %v", err) } - out, _, err := prg.Eval(map[string]interface{}{"x": "hello"}) + out, _, err := prg.Eval(map[string]any{"x": "hello"}) if err != nil { t.Errorf("prg.Eval(x=hello) failed: %v", err) } @@ -292,7 +292,7 @@ func TestSingletonUnaryBindingParameterized(t *testing.T) { if err != nil { t.Fatalf("Program() failed: %v", err) } - out, _, err := prg.Eval(map[string]interface{}{"x": []int{1, 2, 3}}) + out, _, err := prg.Eval(map[string]any{"x": []int{1, 2, 3}}) if err != nil { t.Errorf("prg.Eval(x=[1,2,3]) failed: %v", err) } @@ -455,7 +455,7 @@ func TestUnaryBinding(t *testing.T) { if err != nil { t.Fatalf("Program() failed: %v", err) } - out, _, err := prg.Eval(map[string]interface{}{"x": types.Unknown{1}}) + out, _, err := prg.Eval(map[string]any{"x": types.Unknown{1}}) if err != nil { t.Fatalf("prg.Eval(x=unk) failed: %v", err) } @@ -538,21 +538,21 @@ func TestBinaryBinding(t *testing.T) { if err != nil { t.Fatalf("Program() failed: %v", err) } - out, _, err := prg.Eval(map[string]interface{}{"x": types.Unknown{1}, "y": 1}) + out, _, err := prg.Eval(map[string]any{"x": types.Unknown{1}, "y": 1}) if err != nil { t.Fatalf("prg.Eval(x=unk) failed: %v", err) } if !reflect.DeepEqual(out, types.IntOne) { t.Errorf("prg.Eval(x=unk, y=1) returned %v, wanted 1", out) } - out, _, err = prg.Eval(map[string]interface{}{"x": 2, "y": types.Unknown{2}}) + out, _, err = prg.Eval(map[string]any{"x": 2, "y": types.Unknown{2}}) if err != nil { t.Fatalf("prg.Eval(x=2, y=unk) failed: %v", err) } if !reflect.DeepEqual(out, types.Int(2)) { t.Errorf("prg.Eval(x=2, y=unk) returned %v, wanted 2", out) } - out, _, err = prg.Eval(map[string]interface{}{"x": 2, "y": 1}) + out, _, err = prg.Eval(map[string]any{"x": 2, "y": 1}) if err != nil { t.Fatalf("prg.Eval(x=2, y=1) failed: %v", err) } @@ -1042,7 +1042,7 @@ func TestExprDeclToDeclaration(t *testing.T) { if err != nil { t.Fatalf("Program(ast) failed: %v", err) } - out, _, err := prg.Eval(map[string]interface{}{"x": "hello"}) + out, _, err := prg.Eval(map[string]any{"x": "hello"}) if err != nil { t.Fatalf("prg.Eval(x=hello) failed: %v", err) } @@ -1117,7 +1117,7 @@ func TestExprDeclToDeclarationInvalid(t *testing.T) { } } -func testParse(t testing.TB, env *Env, expr string, want interface{}) { +func testParse(t testing.TB, env *Env, expr string, want any) { t.Helper() ast, iss := env.Parse(expr) if iss.Err() != nil { @@ -1127,7 +1127,7 @@ func testParse(t testing.TB, env *Env, expr string, want interface{}) { if err != nil { t.Fatalf("env.Program() failed: %v", err) } - out, _, err := prg.Eval(map[string]interface{}{"err": types.NewErr("error argument"), "unk": types.Unknown{42}}) + out, _, err := prg.Eval(map[string]any{"err": types.NewErr("error argument"), "unk": types.Unknown{42}}) switch want := want.(type) { case types.Unknown: if !reflect.DeepEqual(want, out.(types.Unknown)) { @@ -1144,7 +1144,7 @@ func testParse(t testing.TB, env *Env, expr string, want interface{}) { } } -func testCompile(t testing.TB, env *Env, expr string, want interface{}) { +func testCompile(t testing.TB, env *Env, expr string, want any) { t.Helper() ast, iss := env.Compile(expr) if iss.Err() != nil { @@ -1154,7 +1154,7 @@ func testCompile(t testing.TB, env *Env, expr string, want interface{}) { if err != nil { t.Fatalf("env.Program() failed: %v", err) } - out, _, err := prg.Eval(map[string]interface{}{"err": types.NewErr("error argument"), "unk": types.Unknown{42}}) + out, _, err := prg.Eval(map[string]any{"err": types.NewErr("error argument"), "unk": types.Unknown{42}}) switch want := want.(type) { case types.Unknown: if !reflect.DeepEqual(want, out.(types.Unknown)) { diff --git a/cel/io_test.go b/cel/io_test.go index ebaa8a77..e6e9699d 100644 --- a/cel/io_test.go +++ b/cel/io_test.go @@ -30,7 +30,7 @@ import ( func TestRefValueToValueRoundTrip(t *testing.T) { tests := []struct { - value interface{} + value any }{ {value: types.NullValue}, {value: types.Bool(true)}, @@ -44,7 +44,7 @@ func TestRefValueToValueRoundTrip(t *testing.T) { {value: types.IntType}, {value: types.NewTypeValue("CustomType")}, {value: map[int64]int64{1: 1}}, - {value: []interface{}{true, "abc"}}, + {value: []any{true, "abc"}}, {value: &proto3pb.TestAllTypes{SingleString: "abc"}}, } diff --git a/cel/options.go b/cel/options.go index 60163e81..a15154f3 100644 --- a/cel/options.go +++ b/cel/options.go @@ -221,7 +221,7 @@ func Abbrevs(qualifiedNames ...string) EnvOption { // environment by default. // // Note: This option must be specified after the CustomTypeProvider option when used together. -func Types(addTypes ...interface{}) EnvOption { +func Types(addTypes ...any) EnvOption { return func(e *Env) (*Env, error) { reg, isReg := e.provider.(ref.TypeRegistry) if !isReg { @@ -258,7 +258,7 @@ func Types(addTypes ...interface{}) EnvOption { // // TypeDescs are hermetic to a single Env object, but may be copied to other Env values via // extension or by re-using the same EnvOption with another NewEnv() call. -func TypeDescs(descs ...interface{}) EnvOption { +func TypeDescs(descs ...any) EnvOption { return func(e *Env) (*Env, error) { reg, isReg := e.provider.(ref.TypeRegistry) if !isReg { @@ -355,8 +355,8 @@ func Functions(funcs ...*functions.Overload) ProgramOption { // variables with the same name provided to the Eval() call. If Globals is used in a Library with // a Lib EnvOption, vars may shadow variables provided by previously added libraries. // -// The vars value may either be an `interpreter.Activation` instance or a `map[string]interface{}`. -func Globals(vars interface{}) ProgramOption { +// The vars value may either be an `interpreter.Activation` instance or a `map[string]any`. +func Globals(vars any) ProgramOption { return func(p *prog) (*prog, error) { defaultVars, err := interpreter.NewActivation(vars) if err != nil { diff --git a/cel/program.go b/cel/program.go index 672c83ef..236fc08a 100644 --- a/cel/program.go +++ b/cel/program.go @@ -31,7 +31,7 @@ import ( type Program interface { // Eval returns the result of an evaluation of the Ast and environment against the input vars. // - // The vars value may either be an `interpreter.Activation` or a `map[string]interface{}`. + // The vars value may either be an `interpreter.Activation` or a `map[string]any`. // // If the `OptTrackState`, `OptTrackCost` or `OptExhaustiveEval` flags are used, the `details` response will // be non-nil. Given this caveat on `details`, the return state from evaluation will be: @@ -43,16 +43,16 @@ type Program interface { // An unsuccessful evaluation is typically the result of a series of incompatible `EnvOption` // or `ProgramOption` values used in the creation of the evaluation environment or executable // program. - Eval(interface{}) (ref.Val, *EvalDetails, error) + Eval(any) (ref.Val, *EvalDetails, error) // ContextEval evaluates the program with a set of input variables and a context object in order // to support cancellation and timeouts. This method must be used in conjunction with the // InterruptCheckFrequency() option for cancellation interrupts to be impact evaluation. // - // The vars value may either be an `interpreter.Activation` or `map[string]interface{}`. + // The vars value may either be an `interpreter.Activation` or `map[string]any`. // // The output contract for `ContextEval` is otherwise identical to the `Eval` method. - ContextEval(context.Context, interface{}) (ref.Val, *EvalDetails, error) + ContextEval(context.Context, any) (ref.Val, *EvalDetails, error) } // NoVars returns an empty Activation. @@ -65,7 +65,7 @@ func NoVars() interpreter.Activation { // // The `vars` value may either be an interpreter.Activation or any valid input to the // interpreter.NewActivation call. -func PartialVars(vars interface{}, +func PartialVars(vars any, unknowns ...*interpreter.AttributePattern) (interpreter.PartialActivation, error) { return interpreter.NewPartialActivation(vars, unknowns...) } @@ -265,7 +265,7 @@ func (p *prog) initInterpretable(ast *Ast, decs []interpreter.InterpretableDecor } // Eval implements the Program interface method. -func (p *prog) Eval(input interface{}) (v ref.Val, det *EvalDetails, err error) { +func (p *prog) Eval(input any) (v ref.Val, det *EvalDetails, err error) { // Configure error recovery for unexpected panics during evaluation. Note, the use of named // return values makes it possible to modify the error response during the recovery // function. @@ -284,11 +284,11 @@ func (p *prog) Eval(input interface{}) (v ref.Val, det *EvalDetails, err error) switch v := input.(type) { case interpreter.Activation: vars = v - case map[string]interface{}: + case map[string]any: vars = activationPool.Setup(v) defer activationPool.Put(vars) default: - return nil, nil, fmt.Errorf("invalid input, wanted Activation or map[string]interface{}, got: (%T)%v", input, input) + return nil, nil, fmt.Errorf("invalid input, wanted Activation or map[string]any, got: (%T)%v", input, input) } if p.defaultVars != nil { vars = interpreter.NewHierarchicalActivation(p.defaultVars, vars) @@ -304,7 +304,7 @@ func (p *prog) Eval(input interface{}) (v ref.Val, det *EvalDetails, err error) } // ContextEval implements the Program interface. -func (p *prog) ContextEval(ctx context.Context, input interface{}) (ref.Val, *EvalDetails, error) { +func (p *prog) ContextEval(ctx context.Context, input any) (ref.Val, *EvalDetails, error) { if ctx == nil { return nil, nil, fmt.Errorf("context can not be nil") } @@ -315,13 +315,13 @@ func (p *prog) ContextEval(ctx context.Context, input interface{}) (ref.Val, *Ev case interpreter.Activation: vars = ctxActivationPool.Setup(v, ctx.Done(), p.interruptCheckFrequency) defer ctxActivationPool.Put(vars) - case map[string]interface{}: + case map[string]any: rawVars := activationPool.Setup(v) defer activationPool.Put(rawVars) vars = ctxActivationPool.Setup(rawVars, ctx.Done(), p.interruptCheckFrequency) defer ctxActivationPool.Put(vars) default: - return nil, nil, fmt.Errorf("invalid input, wanted Activation or map[string]interface{}, got: (%T)%v", input, input) + return nil, nil, fmt.Errorf("invalid input, wanted Activation or map[string]any, got: (%T)%v", input, input) } return p.Eval(vars) } @@ -351,7 +351,7 @@ func newProgGen(factory progFactory) (Program, error) { } // Eval implements the Program interface method. -func (gen *progGen) Eval(input interface{}) (ref.Val, *EvalDetails, error) { +func (gen *progGen) Eval(input any) (ref.Val, *EvalDetails, error) { // The factory based Eval() differs from the standard evaluation model in that it generates a // new EvalState instance for each call to ensure that unique evaluations yield unique stateful // results. @@ -376,7 +376,7 @@ func (gen *progGen) Eval(input interface{}) (ref.Val, *EvalDetails, error) { } // ContextEval implements the Program interface method. -func (gen *progGen) ContextEval(ctx context.Context, input interface{}) (ref.Val, *EvalDetails, error) { +func (gen *progGen) ContextEval(ctx context.Context, input any) (ref.Val, *EvalDetails, error) { if ctx == nil { return nil, nil, fmt.Errorf("context can not be nil") } @@ -418,7 +418,7 @@ func EstimateCost(p Program) (min, max int64) { return estimateCost(p) } -func estimateCost(i interface{}) (min, max int64) { +func estimateCost(i any) (min, max int64) { c, ok := i.(interpreter.Coster) if !ok { return 0, math.MaxInt64 @@ -435,7 +435,7 @@ type ctxEvalActivation struct { // ResolveName implements the Activation interface method, but adds a special #interrupted variable // which is capable of testing whether a 'done' signal is provided from a context.Context channel. -func (a *ctxEvalActivation) ResolveName(name string) (interface{}, bool) { +func (a *ctxEvalActivation) ResolveName(name string) (any, bool) { if name == "#interrupted" { a.interruptCheckCount++ if a.interruptCheckCount%a.interruptCheckFrequency == 0 { @@ -458,7 +458,7 @@ func (a *ctxEvalActivation) Parent() interpreter.Activation { func newCtxEvalActivationPool() *ctxEvalActivationPool { return &ctxEvalActivationPool{ Pool: sync.Pool{ - New: func() interface{} { + New: func() any { return &ctxEvalActivation{} }, }, @@ -480,21 +480,21 @@ func (p *ctxEvalActivationPool) Setup(vars interpreter.Activation, done <-chan s } type evalActivation struct { - vars map[string]interface{} - lazyVars map[string]interface{} + vars map[string]any + lazyVars map[string]any } // ResolveName looks up the value of the input variable name, if found. // // Lazy bindings may be supplied within the map-based input in either of the following forms: -// - func() interface{} +// - func() any // - func() ref.Val // // The lazy binding will only be invoked once per evaluation. // // Values which are not represented as ref.Val types on input may be adapted to a ref.Val using // the ref.TypeAdapter configured in the environment. -func (a *evalActivation) ResolveName(name string) (interface{}, bool) { +func (a *evalActivation) ResolveName(name string) (any, bool) { v, found := a.vars[name] if !found { return nil, false @@ -507,7 +507,7 @@ func (a *evalActivation) ResolveName(name string) (interface{}, bool) { lazy := obj() a.lazyVars[name] = lazy return lazy, true - case func() interface{}: + case func() any: if resolved, found := a.lazyVars[name]; found { return resolved, true } @@ -527,8 +527,8 @@ func (a *evalActivation) Parent() interpreter.Activation { func newEvalActivationPool() *evalActivationPool { return &evalActivationPool{ Pool: sync.Pool{ - New: func() interface{} { - return &evalActivation{lazyVars: make(map[string]interface{})} + New: func() any { + return &evalActivation{lazyVars: make(map[string]any)} }, }, } @@ -539,13 +539,13 @@ type evalActivationPool struct { } // Setup initializes a pooled Activation object with the map input. -func (p *evalActivationPool) Setup(vars map[string]interface{}) *evalActivation { +func (p *evalActivationPool) Setup(vars map[string]any) *evalActivation { a := p.Pool.Get().(*evalActivation) a.vars = vars return a } -func (p *evalActivationPool) Put(value interface{}) { +func (p *evalActivationPool) Put(value any) { a := value.(*evalActivation) for k := range a.lazyVars { delete(a.lazyVars, k) @@ -556,7 +556,7 @@ func (p *evalActivationPool) Put(value interface{}) { var ( emptyEvalState = interpreter.NewEvalState() - // activationPool is an internally managed pool of Activation values that wrap map[string]interface{} inputs + // activationPool is an internally managed pool of Activation values that wrap map[string]any inputs activationPool = newEvalActivationPool() // ctxActivationPool is an internally managed pool of Activation values that expose a special #interrupted variable diff --git a/checker/checker.go b/checker/checker.go index fcddb1b2..04f32503 100644 --- a/checker/checker.go +++ b/checker/checker.go @@ -173,8 +173,8 @@ func (c *checker) checkSelect(e *exprpb.Expr) { // Rewrite the node to be a variable reference to the resolved fully-qualified // variable name. - c.setType(e, ident.GetIdent().Type) - c.setReference(e, newIdentReference(ident.GetName(), ident.GetIdent().Value)) + c.setType(e, ident.GetIdent().GetType()) + c.setReference(e, newIdentReference(ident.GetName(), ident.GetIdent().GetValue())) identName := ident.GetName() e.ExprKind = &exprpb.Expr_IdentExpr{ IdentExpr: &exprpb.Expr_Ident{ diff --git a/checker/printer.go b/checker/printer.go index e2ed35be..0cecc521 100644 --- a/checker/printer.go +++ b/checker/printer.go @@ -26,7 +26,7 @@ type semanticAdorner struct { var _ debug.Adorner = &semanticAdorner{} -func (a *semanticAdorner) GetMetadata(elem interface{}) string { +func (a *semanticAdorner) GetMetadata(elem any) string { result := "" e, isExpr := elem.(*exprpb.Expr) if !isExpr { diff --git a/codelab/codelab.go b/codelab/codelab.go index 562247c4..f533e700 100644 --- a/codelab/codelab.go +++ b/codelab/codelab.go @@ -161,8 +161,8 @@ func compile(env *cel.Env, expr string, celType *cel.Type) *cel.Ast { // and return the output, eval details (optional), or error that results from // evaluation. func eval(prg cel.Program, - vars interface{}) (out ref.Val, det *cel.EvalDetails, err error) { - varMap, isMap := vars.(map[string]interface{}) + vars any) (out ref.Val, det *cel.EvalDetails, err error) { + varMap, isMap := vars.(map[string]any) fmt.Println("------ input ------") if !isMap { fmt.Printf("(%T)\n", vars) @@ -175,7 +175,7 @@ func eval(prg cel.Program, glog.Exitf("failed to marshal proto to text: %v", val) } fmt.Printf("%s = %s", k, string(bytes)) - case map[string]interface{}: + case map[string]any: b, _ := json.MarshalIndent(v, "", " ") fmt.Printf("%s = %v\n", k, string(b)) case uint64: @@ -261,12 +261,12 @@ func auth(user string, claims map[string]string) *rpcpb.AttributeContext_Auth { } // request constructs a `google.rpc.context.AttributeContext.Request` message. -func request(auth *rpcpb.AttributeContext_Auth, t time.Time) map[string]interface{} { +func request(auth *rpcpb.AttributeContext_Auth, t time.Time) map[string]any { req := &rpcpb.AttributeContext_Request{ Auth: auth, Time: &tpb.Timestamp{Seconds: t.Unix()}, } - return map[string]interface{}{"request": req} + return map[string]any{"request": req} } // valueToJSON converts the CEL type to a protobuf JSON representation and diff --git a/codelab/solution/codelab.go b/codelab/solution/codelab.go index 207ff11b..b1bfb95d 100644 --- a/codelab/solution/codelab.go +++ b/codelab/solution/codelab.go @@ -222,7 +222,7 @@ func exercise5() { program, _ := env.Program(ast) out, _, _ := eval( program, - map[string]interface{}{ + map[string]any{ "now": time.Now(), }, ) @@ -273,8 +273,8 @@ func exercise6() { // Construct the message. The result is a ref.Val that returns a dynamic proto message. out, _, _ := eval( program, - map[string]interface{}{ - "jwt": map[string]interface{}{ + map[string]any{ + "jwt": map[string]any{ "sub": "serviceAccount:delegate@acme.co", "aud": "my-project", "iss": "auth.acme.com:12350", @@ -319,8 +319,8 @@ func exercise7() { // Evaluate a complex-ish JWT with two groups that satisfy the criteria. // Output: true. eval(program, - map[string]interface{}{ - "jwt": map[string]interface{}{ + map[string]any{ + "jwt": map[string]any{ "sub": "serviceAccount:delegate@acme.co", "aud": "my-project", "iss": "auth.acme.com:12350", @@ -351,7 +351,7 @@ func exercise8() { `x in [1, 2, 3, 4, 5] && type(y) == uint`, cel.BoolType) // Turn on optimization. - trueVars := map[string]interface{}{"x": int64(4), "y": uint64(2)} + trueVars := map[string]any{"x": int64(4), "y": uint64(2)} program, _ := env.Program(ast, cel.EvalOptions(cel.OptOptimize)) // Try benchmarking this evaluation with the optimization flag on and off. eval(program, trueVars) @@ -359,13 +359,13 @@ func exercise8() { // Turn on exhaustive eval to see what the evaluation state looks like. // The input is structure to show a false on the first branch, and true // on the second. - falseVars := map[string]interface{}{"x": int64(6), "y": uint64(2)} + falseVars := map[string]any{"x": int64(6), "y": uint64(2)} program, _ = env.Program(ast, cel.EvalOptions(cel.OptExhaustiveEval)) eval(program, falseVars) // Turn on optimization and state tracking to see the typical eval // behavior, but with partial input. - xVar := map[string]interface{}{"x": int64(3)} + xVar := map[string]any{"x": int64(3)} partialVars, _ := cel.PartialVars(xVar, cel.AttributePattern("y")) program, _ = env.Program(ast, cel.EvalOptions(cel.OptPartialEval, cel.OptOptimize, cel.OptTrackState)) @@ -402,8 +402,8 @@ func compile(env *cel.Env, expr string, celType *cel.Type) *cel.Ast { // and return the output, eval details (optional), or error that results from // evaluation. func eval(prg cel.Program, - vars interface{}) (out ref.Val, det *cel.EvalDetails, err error) { - varMap, isMap := vars.(map[string]interface{}) + vars any) (out ref.Val, det *cel.EvalDetails, err error) { + varMap, isMap := vars.(map[string]any) fmt.Println("------ input ------") if !isMap { fmt.Printf("(%T)\n", vars) @@ -416,7 +416,7 @@ func eval(prg cel.Program, glog.Exitf("failed to marshal proto to text: %v", val) } fmt.Printf("%s = %s", k, string(bytes)) - case map[string]interface{}: + case map[string]any: b, _ := json.MarshalIndent(v, "", " ") fmt.Printf("%s = %v\n", k, string(b)) case uint64: @@ -502,12 +502,12 @@ func auth(user string, claims map[string]string) *rpcpb.AttributeContext_Auth { } // request constructs a `google.rpc.context.AttributeContext.Request` message. -func request(auth *rpcpb.AttributeContext_Auth, t time.Time) map[string]interface{} { +func request(auth *rpcpb.AttributeContext_Auth, t time.Time) map[string]any { req := &rpcpb.AttributeContext_Request{ Auth: auth, Time: &tpb.Timestamp{Seconds: t.Unix()}, } - return map[string]interface{}{"request": req} + return map[string]any{"request": req} } // valueToJSON converts the CEL type to a protobuf JSON representation and diff --git a/common/debug/debug.go b/common/debug/debug.go index bec88542..d0c659b0 100644 --- a/common/debug/debug.go +++ b/common/debug/debug.go @@ -29,7 +29,7 @@ import ( // representation of an expression. type Adorner interface { // GetMetadata for the input context. - GetMetadata(ctx interface{}) string + GetMetadata(ctx any) string } // Writer manages writing expressions to an internal string. @@ -46,7 +46,7 @@ type emptyDebugAdorner struct { var emptyAdorner Adorner = &emptyDebugAdorner{} -func (a *emptyDebugAdorner) GetMetadata(e interface{}) string { +func (a *emptyDebugAdorner) GetMetadata(e any) string { return "" } @@ -269,7 +269,7 @@ func (w *debugWriter) append(s string) { w.buffer.WriteString(s) } -func (w *debugWriter) appendFormat(f string, args ...interface{}) { +func (w *debugWriter) appendFormat(f string, args ...any) { w.append(fmt.Sprintf(f, args...)) } @@ -280,7 +280,7 @@ func (w *debugWriter) doIndent() { } } -func (w *debugWriter) adorn(e interface{}) { +func (w *debugWriter) adorn(e any) { w.append(w.adorner.GetMetadata(e)) } diff --git a/common/errors.go b/common/errors.go index daebba86..1565085a 100644 --- a/common/errors.go +++ b/common/errors.go @@ -38,7 +38,7 @@ func NewErrors(source Source) *Errors { } // ReportError records an error at a source location. -func (e *Errors) ReportError(l Location, format string, args ...interface{}) { +func (e *Errors) ReportError(l Location, format string, args ...any) { e.numErrors++ if e.numErrors > e.maxErrorsToReport { return diff --git a/common/operators/operators.go b/common/operators/operators.go index fa25dfb7..f9b39bda 100644 --- a/common/operators/operators.go +++ b/common/operators/operators.go @@ -37,6 +37,8 @@ const ( Modulo = "_%_" Negate = "-_" Index = "_[_]" + OptIndex = "_[?_]" + OptSelect = "_?._" // Macros, must have a valid identifier. Has = "has" @@ -99,6 +101,8 @@ var ( LogicalNot: {displayName: "!", precedence: 2, arity: 1}, Negate: {displayName: "-", precedence: 2, arity: 1}, Index: {displayName: "", precedence: 1, arity: 2}, + OptIndex: {displayName: "", precedence: 1, arity: 2}, + OptSelect: {displayName: "", precedence: 1, arity: 2}, } ) diff --git a/common/types/bool.go b/common/types/bool.go index 386c481c..a634ecc2 100644 --- a/common/types/bool.go +++ b/common/types/bool.go @@ -62,7 +62,7 @@ func (b Bool) Compare(other ref.Val) ref.Val { } // ConvertToNative implements the ref.Val interface method. -func (b Bool) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { +func (b Bool) ConvertToNative(typeDesc reflect.Type) (any, error) { switch typeDesc.Kind() { case reflect.Bool: return reflect.ValueOf(b).Convert(typeDesc).Interface(), nil @@ -130,7 +130,7 @@ func (b Bool) Type() ref.Type { } // Value implements the ref.Val interface method. -func (b Bool) Value() interface{} { +func (b Bool) Value() any { return bool(b) } diff --git a/common/types/bytes.go b/common/types/bytes.go index 141a0217..bef19075 100644 --- a/common/types/bytes.go +++ b/common/types/bytes.go @@ -63,7 +63,7 @@ func (b Bytes) Compare(other ref.Val) ref.Val { } // ConvertToNative implements the ref.Val interface method. -func (b Bytes) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { +func (b Bytes) ConvertToNative(typeDesc reflect.Type) (any, error) { switch typeDesc.Kind() { case reflect.Array, reflect.Slice: return reflect.ValueOf(b).Convert(typeDesc).Interface(), nil @@ -132,6 +132,6 @@ func (b Bytes) Type() ref.Type { } // Value implements the ref.Val interface method. -func (b Bytes) Value() interface{} { +func (b Bytes) Value() any { return []byte(b) } diff --git a/common/types/double.go b/common/types/double.go index 5167d01d..4647cf04 100644 --- a/common/types/double.go +++ b/common/types/double.go @@ -78,7 +78,7 @@ func (d Double) Compare(other ref.Val) ref.Val { } // ConvertToNative implements ref.Val.ConvertToNative. -func (d Double) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { +func (d Double) ConvertToNative(typeDesc reflect.Type) (any, error) { switch typeDesc.Kind() { case reflect.Float32: v := float32(d) @@ -216,6 +216,6 @@ func (d Double) Type() ref.Type { } // Value implements ref.Val.Value. -func (d Double) Value() interface{} { +func (d Double) Value() any { return float64(d) } diff --git a/common/types/double_test.go b/common/types/double_test.go index 0855edec..239e74d3 100644 --- a/common/types/double_test.go +++ b/common/types/double_test.go @@ -250,7 +250,7 @@ func TestDoubleConvertToType(t *testing.T) { name string in float64 toType ref.Type - out interface{} + out any }{ { name: "DoubleToDouble", diff --git a/common/types/duration.go b/common/types/duration.go index 28e3482e..f6a4f5a0 100644 --- a/common/types/duration.go +++ b/common/types/duration.go @@ -90,7 +90,7 @@ func (d Duration) Compare(other ref.Val) ref.Val { } // ConvertToNative implements ref.Val.ConvertToNative. -func (d Duration) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { +func (d Duration) ConvertToNative(typeDesc reflect.Type) (any, error) { // If the duration is already assignable to the desired type return it. if reflect.TypeOf(d.Duration).AssignableTo(typeDesc) { return d.Duration, nil @@ -181,7 +181,7 @@ func (d Duration) Type() ref.Type { } // Value implements ref.Val.Value. -func (d Duration) Value() interface{} { +func (d Duration) Value() any { return d.Duration } diff --git a/common/types/duration_test.go b/common/types/duration_test.go index 94481977..d5217053 100644 --- a/common/types/duration_test.go +++ b/common/types/duration_test.go @@ -40,7 +40,7 @@ func TestDurationOperators(t *testing.T) { tests := []struct { name string op func() ref.Val - out interface{} + out any }{ // Addition tests. { diff --git a/common/types/err.go b/common/types/err.go index 9d3f1abf..d9f9b601 100644 --- a/common/types/err.go +++ b/common/types/err.go @@ -51,7 +51,7 @@ var ( // NewErr creates a new Err described by the format string and args. // TODO: Audit the use of this function and standardize the error messages and codes. -func NewErr(format string, args ...interface{}) ref.Val { +func NewErr(format string, args ...any) ref.Val { return &Err{fmt.Errorf(format, args...)} } @@ -62,7 +62,7 @@ func NoSuchOverloadErr() ref.Val { // UnsupportedRefValConversionErr returns a types.NewErr instance with a no such conversion // message that indicates that the native value could not be converted to a CEL ref.Val. -func UnsupportedRefValConversionErr(val interface{}) ref.Val { +func UnsupportedRefValConversionErr(val any) ref.Val { return NewErr("unsupported conversion to ref.Val: (%T)%v", val, val) } @@ -74,7 +74,7 @@ func MaybeNoSuchOverloadErr(val ref.Val) ref.Val { // ValOrErr either returns the existing error or creates a new one. // TODO: Audit the use of this function and standardize the error messages and codes. -func ValOrErr(val ref.Val, format string, args ...interface{}) ref.Val { +func ValOrErr(val ref.Val, format string, args ...any) ref.Val { if val == nil || !IsUnknownOrError(val) { return NewErr(format, args...) } @@ -87,7 +87,7 @@ func wrapErr(err error) ref.Val { } // ConvertToNative implements ref.Val.ConvertToNative. -func (e *Err) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { +func (e *Err) ConvertToNative(typeDesc reflect.Type) (any, error) { return nil, e.error } @@ -114,7 +114,7 @@ func (e *Err) Type() ref.Type { } // Value implements ref.Val.Value. -func (e *Err) Value() interface{} { +func (e *Err) Value() any { return e.error } diff --git a/common/types/int.go b/common/types/int.go index 962b159a..5f13956e 100644 --- a/common/types/int.go +++ b/common/types/int.go @@ -89,7 +89,7 @@ func (i Int) Compare(other ref.Val) ref.Val { } // ConvertToNative implements ref.Val.ConvertToNative. -func (i Int) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { +func (i Int) ConvertToNative(typeDesc reflect.Type) (any, error) { switch typeDesc.Kind() { case reflect.Int, reflect.Int32: // Enums are also mapped as int32 derivations. @@ -285,7 +285,7 @@ func (i Int) Type() ref.Type { } // Value implements ref.Val.Value. -func (i Int) Value() interface{} { +func (i Int) Value() any { return int64(i) } diff --git a/common/types/int_test.go b/common/types/int_test.go index 8f62a663..9f76bb77 100644 --- a/common/types/int_test.go +++ b/common/types/int_test.go @@ -262,7 +262,7 @@ func TestIntConvertToType(t *testing.T) { name string in int64 toType ref.Type - out interface{} + out any }{ { name: "IntToType", diff --git a/common/types/iterator.go b/common/types/iterator.go index 49066277..9f224ad4 100644 --- a/common/types/iterator.go +++ b/common/types/iterator.go @@ -34,7 +34,7 @@ var ( // interpreter. type baseIterator struct{} -func (*baseIterator) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { +func (*baseIterator) ConvertToNative(typeDesc reflect.Type) (any, error) { return nil, fmt.Errorf("type conversion on iterators not supported") } @@ -50,6 +50,6 @@ func (*baseIterator) Type() ref.Type { return IteratorType } -func (*baseIterator) Value() interface{} { +func (*baseIterator) Value() any { return nil } diff --git a/common/types/json_struct_test.go b/common/types/json_struct_test.go index bf3058b4..00c9856d 100644 --- a/common/types/json_struct_test.go +++ b/common/types/json_struct_test.go @@ -142,7 +142,7 @@ func TestJsonStructEqual(t *testing.T) { mapVal, other) } mismatch := NewDynamicMap(reg, - map[int]interface{}{ + map[int]any{ 1: "hello", 2: "world"}) if IsError(mapVal.Equal(mismatch)) { diff --git a/common/types/list.go b/common/types/list.go index ff649e68..830c7ee6 100644 --- a/common/types/list.go +++ b/common/types/list.go @@ -42,13 +42,13 @@ var ( // NewDynamicList returns a traits.Lister with heterogenous elements. // value should be an array of "native" types, i.e. any type that // NativeToValue() can convert to a ref.Val. -func NewDynamicList(adapter ref.TypeAdapter, value interface{}) traits.Lister { +func NewDynamicList(adapter ref.TypeAdapter, value any) traits.Lister { refValue := reflect.ValueOf(value) return &baseList{ TypeAdapter: adapter, value: value, size: refValue.Len(), - get: func(i int) interface{} { + get: func(i int) any { return refValue.Index(i).Interface() }, } @@ -60,7 +60,7 @@ func NewStringList(adapter ref.TypeAdapter, elems []string) traits.Lister { TypeAdapter: adapter, value: elems, size: len(elems), - get: func(i int) interface{} { return elems[i] }, + get: func(i int) any { return elems[i] }, } } @@ -72,7 +72,7 @@ func NewRefValList(adapter ref.TypeAdapter, elems []ref.Val) traits.Lister { TypeAdapter: adapter, value: elems, size: len(elems), - get: func(i int) interface{} { return elems[i] }, + get: func(i int) any { return elems[i] }, } } @@ -82,7 +82,7 @@ func NewProtoList(adapter ref.TypeAdapter, list protoreflect.List) traits.Lister TypeAdapter: adapter, value: list, size: list.Len(), - get: func(i int) interface{} { return list.Get(i).Interface() }, + get: func(i int) any { return list.Get(i).Interface() }, } } @@ -93,7 +93,7 @@ func NewJSONList(adapter ref.TypeAdapter, l *structpb.ListValue) traits.Lister { TypeAdapter: adapter, value: l, size: len(vals), - get: func(i int) interface{} { return vals[i] }, + get: func(i int) any { return vals[i] }, } } @@ -108,7 +108,7 @@ func NewMutableList(adapter ref.TypeAdapter) traits.MutableLister { }, mutableValues: mutableValues, } - l.get = func(i int) interface{} { + l.get = func(i int) any { return l.mutableValues[i] } return l @@ -119,7 +119,7 @@ func NewMutableList(adapter ref.TypeAdapter) traits.MutableLister { // The `ref.TypeAdapter` enables native type to CEL type conversions. type baseList struct { ref.TypeAdapter - value interface{} + value any // size indicates the number of elements within the list. // Since objects are immutable the size of a list is static. @@ -127,7 +127,7 @@ type baseList struct { // get returns a value at the specified integer index. // The index is guaranteed to be checked against the list index range. - get func(int) interface{} + get func(int) any } // Add implements the traits.Adder interface method. @@ -162,7 +162,7 @@ func (l *baseList) Contains(elem ref.Val) ref.Val { } // ConvertToNative implements the ref.Val interface method. -func (l *baseList) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { +func (l *baseList) ConvertToNative(typeDesc reflect.Type) (any, error) { // If the underlying list value is assignable to the reflected type return it. if reflect.TypeOf(l.value).AssignableTo(typeDesc) { return l.value, nil @@ -276,7 +276,7 @@ func (l *baseList) Type() ref.Type { } // Value implements the ref.Val interface method. -func (l *baseList) Value() interface{} { +func (l *baseList) Value() any { return l.value } @@ -329,7 +329,7 @@ func (l *mutableList) ToImmutableList() traits.Lister { // The `ref.TypeAdapter` enables native type to CEL type conversions. type concatList struct { ref.TypeAdapter - value interface{} + value any prevList traits.Lister nextList traits.Lister } @@ -375,8 +375,8 @@ func (l *concatList) Contains(elem ref.Val) ref.Val { } // ConvertToNative implements the ref.Val interface method. -func (l *concatList) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { - combined := NewDynamicList(l.TypeAdapter, l.Value().([]interface{})) +func (l *concatList) ConvertToNative(typeDesc reflect.Type) (any, error) { + combined := NewDynamicList(l.TypeAdapter, l.Value().([]any)) return combined.ConvertToNative(typeDesc) } @@ -467,9 +467,9 @@ func (l *concatList) Type() ref.Type { } // Value implements the ref.Val interface method. -func (l *concatList) Value() interface{} { +func (l *concatList) Value() any { if l.value == nil { - merged := make([]interface{}, l.Size().(Int)) + merged := make([]any, l.Size().(Int)) prevLen := l.prevList.Size().(Int) for i := Int(0); i < prevLen; i++ { merged[i] = l.prevList.Get(i).Value() diff --git a/common/types/list_test.go b/common/types/list_test.go index ff15bf81..7e47ff5d 100644 --- a/common/types/list_test.go +++ b/common/types/list_test.go @@ -164,11 +164,11 @@ func TestBaseListEqual(t *testing.T) { if listA.Equal(listB) != False { t.Error("listA.Equal(listB) did not return false.") } - listC := reg.NativeToValue([]interface{}{"h", "e", "l", "l", String("o")}) + listC := reg.NativeToValue([]any{"h", "e", "l", "l", String("o")}) if listA.Equal(listC) != True { t.Error("listA.Equal(listC) did not return true.") } - listD := reg.NativeToValue([]interface{}{"h", "e", 1, "p", "!"}) + listD := reg.NativeToValue([]any{"h", "e", 1, "p", "!"}) if listA.Equal(listD) != False { t.Error("listA.Equal(listD) did not return true") } @@ -182,7 +182,7 @@ func TestBaseListGet(t *testing.T) { } func TestBaseListString(t *testing.T) { - l := DefaultTypeAdapter.NativeToValue([]interface{}{1, "hello", 2.1, true, []string{"world"}}) + l := DefaultTypeAdapter.NativeToValue([]any{1, "hello", 2.1, true, []string{"world"}}) want := `[1, hello, 2.1, true, [world]]` if fmt.Sprintf("%v", l) != want { t.Errorf("l.String() got %v, wanted %v", l, want) @@ -190,7 +190,7 @@ func TestBaseListString(t *testing.T) { } func TestConcatListString(t *testing.T) { - l := DefaultTypeAdapter.NativeToValue([]interface{}{1, "hello", 2.1, true}).(traits.Lister) + l := DefaultTypeAdapter.NativeToValue([]any{1, "hello", 2.1, true}).(traits.Lister) c := l.Add(DefaultTypeAdapter.NativeToValue([]string{"world"})) want := `[1, hello, 2.1, true, world]` if fmt.Sprintf("%v", c) != want { @@ -200,7 +200,7 @@ func TestConcatListString(t *testing.T) { func TestListIsZeroValue(t *testing.T) { tests := []struct { - val interface{} + val any isZeroValue bool }{ { @@ -212,7 +212,7 @@ func TestListIsZeroValue(t *testing.T) { isZeroValue: true, }, { - val: []interface{}{}, + val: []any{}, isZeroValue: true, }, { @@ -236,7 +236,7 @@ func TestListIsZeroValue(t *testing.T) { isZeroValue: false, }, { - val: []interface{}{0}, + val: []any{0}, isZeroValue: false, }, { @@ -282,9 +282,9 @@ func TestValueListValue_Iterator(t *testing.T) { func TestBaseListNestedList(t *testing.T) { reg := newTestRegistry(t) listUint32 := []uint32{1, 2} - nestedUint32 := NewDynamicList(reg, []interface{}{listUint32}) + nestedUint32 := NewDynamicList(reg, []any{listUint32}) listUint64 := []uint64{1, 2} - nestedUint64 := NewDynamicList(reg, []interface{}{listUint64}) + nestedUint64 := NewDynamicList(reg, []any{listUint64}) if nestedUint32.Equal(nestedUint64) != True { t.Error("Could not find nested list") } @@ -297,7 +297,7 @@ func TestBaseListNestedList(t *testing.T) { func TestBaseListSize(t *testing.T) { reg := newTestRegistry(t) listUint32 := []uint32{1, 2} - nestedUint32 := NewDynamicList(reg, []interface{}{listUint32}) + nestedUint32 := NewDynamicList(reg, []any{listUint32}) if nestedUint32.Size() != IntOne { t.Error("List indicates the incorrect size.") } @@ -324,8 +324,8 @@ func TestConcatListAdd(t *testing.T) { listA := NewDynamicList(reg, []float32{1.0, 2.0}) listB := NewStringList(reg, []string{"3"}) list := listA.Add(listB).(traits.Lister).Add(listA). - Value().([]interface{}) - expected := []interface{}{ + Value().([]any) + expected := []any{ float64(1.0), float64(2.0), string("3"), @@ -368,13 +368,13 @@ func TestConcatListConvertToNative_Json(t *testing.T) { t.Fatalf("protojson.Marshal(%v) failed: %v", jsonVal, err) } jsonTxt := string(jsonBytes) - outList := []interface{}{} + outList := []any{} err = json.Unmarshal(jsonBytes, &outList) if err != nil { t.Fatalf("json.Unmarshal(%q) failed: %v", jsonTxt, err) } - if !reflect.DeepEqual(outList, []interface{}{1.0, 2.0, "3"}) { - t.Errorf("got json '%v', expected %v", outList, []interface{}{1.0, 2.0, "3"}) + if !reflect.DeepEqual(outList, []any{1.0, 2.0, "3"}) { + t.Errorf("got json '%v', expected %v", outList, []any{1.0, 2.0, "3"}) } // Test proto3 to JSON conversion. listC := NewDynamicList(reg, []*dpb.Duration{{Seconds: 100}}) @@ -388,13 +388,13 @@ func TestConcatListConvertToNative_Json(t *testing.T) { t.Fatalf("protojson.Marshal(%v) failed: %v", jsonVal, err) } jsonTxt = string(jsonBytes) - outList = []interface{}{} + outList = []any{} err = json.Unmarshal(jsonBytes, &outList) if err != nil { t.Fatalf("json.Unmarshal(%q) failed: %v", jsonTxt, err) } - if !reflect.DeepEqual(outList, []interface{}{1.0, 2.0, "100s"}) { - t.Errorf("got json '%v', expected %v", outList, []interface{}{1.0, 2.0, "100s"}) + if !reflect.DeepEqual(outList, []any{1.0, 2.0, "100s"}) { + t.Errorf("got json '%v', expected %v", outList, []any{1.0, 2.0, "100s"}) } } @@ -403,11 +403,11 @@ func TestConcatListConvertToNativeListInterface(t *testing.T) { listA := NewDynamicList(reg, []float32{1.0, 2.0}) listB := NewStringList(reg, []string{"3.0"}) list := listA.Add(listB) - iface, err := list.ConvertToNative(reflect.TypeOf([]interface{}{})) + iface, err := list.ConvertToNative(reflect.TypeOf([]any{})) if err != nil { t.Errorf("Got '%v', expected '%v'", err, list) } - want := []interface{}{1.0, 2.0, "3.0"} + want := []any{1.0, 2.0, "3.0"} if !reflect.DeepEqual(iface, want) { t.Errorf("Got '%v', expected '%v'", iface, want) } @@ -463,18 +463,18 @@ func TestConcatListEqual(t *testing.T) { listB := NewDynamicList(reg, []float64{3.0}) list := listA.Add(listB) // Note the internal type of list raw and concat list are slightly different. - listRaw := NewDynamicList(reg, []interface{}{float32(1.0), float64(2.0), float64(3.0)}) + listRaw := NewDynamicList(reg, []any{float32(1.0), float64(2.0), float64(3.0)}) if listRaw.Equal(list) != True || list.Equal(listRaw) != True { t.Errorf("listRaw.Equal(list) not true, got '%v', expected '%v'", list.Value(), listRaw.Value()) } if list.Equal(listA) == True || listRaw.Equal(listA) == True { t.Error("lists of unequal length considered equal") } - listC := reg.NativeToValue([]interface{}{1.0, 3.0, 2.0}) + listC := reg.NativeToValue([]any{1.0, 3.0, 2.0}) if list.Equal(listC) != False { t.Errorf("list.Equal(listC) got %v, wanted false", list.Equal(listC)) } - listD := reg.NativeToValue([]interface{}{1, 2.0, 3.0}) + listD := reg.NativeToValue([]any{1, 2.0, 3.0}) if list.Equal(listD) != True { t.Errorf("list.Equal(listD) got %v, wanted true", list.Equal(listD)) } @@ -545,8 +545,8 @@ func TestStringListAdd_Heterogenous(t *testing.T) { reg := newTestRegistry(t) listA := NewStringList(reg, []string{"hello"}) listB := NewDynamicList(reg, []int32{1, 2, 3}) - list := listA.Add(listB).(traits.Lister).Value().([]interface{}) - expected := []interface{}{"hello", int64(1), int64(2), int64(3)} + list := listA.Add(listB).(traits.Lister).Value().([]any) + expected := []any{"hello", int64(1), int64(2), int64(3)} if len(list) != len(expected) { t.Errorf("Unexpected list size. Got '%d', expected 4", len(list)) } @@ -588,13 +588,13 @@ func TestStringListConvertToNative(t *testing.T) { func TestStringListConvertToNative_ListInterface(t *testing.T) { reg := newTestRegistry(t) list := NewStringList(reg, []string{"h", "e", "l", "p"}) - val, err := list.ConvertToNative(reflect.TypeOf([]interface{}{})) + val, err := list.ConvertToNative(reflect.TypeOf([]any{})) if err != nil { t.Error("Unable to convert string list to itself.") } - want := []interface{}{"h", "e", "l", "p"} - if !reflect.DeepEqual(val.([]interface{}), want) { - for i, e := range val.([]interface{}) { + want := []any{"h", "e", "l", "p"} + if !reflect.DeepEqual(val.([]any), want) { + for i, e := range val.([]any) { t.Logf("val[%d] %v(%T)", i, e, e) } for i, e := range want { @@ -625,12 +625,12 @@ func TestStringListConvertToNative_Json(t *testing.T) { t.Fatalf("protojson.Marshal(%v) failed: %v", jsonVal, err) } jsonTxt := string(jsonBytes) - outList := []interface{}{} + outList := []any{} err = json.Unmarshal(jsonBytes, &outList) if err != nil { t.Fatalf("json.Unmarshal(%q) failed: %v", jsonTxt, err) } - if !reflect.DeepEqual(outList, []interface{}{"h", "e", "l", "p"}) { + if !reflect.DeepEqual(outList, []any{"h", "e", "l", "p"}) { t.Errorf("got json '%v', expected %v", jsonTxt, outList) } @@ -690,17 +690,17 @@ func TestValueListConvertToNative_Json(t *testing.T) { t.Fatalf("protojson.Marshal(%v) failed: %v", jsonVal, err) } jsonTxt := string(jsonBytes) - outList := []interface{}{} + outList := []any{} err = json.Unmarshal(jsonBytes, &outList) if err != nil { t.Fatalf("json.Unmarshal(%q) failed: %v", jsonTxt, err) } - if !reflect.DeepEqual(outList, []interface{}{"hello", "world"}) { + if !reflect.DeepEqual(outList, []any{"hello", "world"}) { t.Errorf("got json '%v', expected %v", jsonTxt, outList) } } -func getElem(t *testing.T, list traits.Indexer, index ref.Val) interface{} { +func getElem(t *testing.T, list traits.Indexer, index ref.Val) any { t.Helper() val := list.Get(index) if IsError(val) { diff --git a/common/types/map.go b/common/types/map.go index facc87c5..213be4ac 100644 --- a/common/types/map.go +++ b/common/types/map.go @@ -32,7 +32,7 @@ import ( ) // NewDynamicMap returns a traits.Mapper value with dynamic key, value pairs. -func NewDynamicMap(adapter ref.TypeAdapter, value interface{}) traits.Mapper { +func NewDynamicMap(adapter ref.TypeAdapter, value any) traits.Mapper { refValue := reflect.ValueOf(value) return &baseMap{ TypeAdapter: adapter, @@ -67,7 +67,7 @@ func NewRefValMap(adapter ref.TypeAdapter, value map[ref.Val]ref.Val) traits.Map } // NewStringInterfaceMap returns a specialized traits.Mapper with string keys and interface values. -func NewStringInterfaceMap(adapter ref.TypeAdapter, value map[string]interface{}) traits.Mapper { +func NewStringInterfaceMap(adapter ref.TypeAdapter, value map[string]any) traits.Mapper { return &baseMap{ TypeAdapter: adapter, mapAccessor: newStringIfaceMapAccessor(adapter, value), @@ -127,7 +127,7 @@ type baseMap struct { mapAccessor // value is the native Go value upon which the map type operators. - value interface{} + value any // size is the number of entries in the map. size int @@ -140,7 +140,7 @@ func (m *baseMap) Contains(index ref.Val) ref.Val { } // ConvertToNative implements the ref.Val interface method. -func (m *baseMap) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { +func (m *baseMap) ConvertToNative(typeDesc reflect.Type) (any, error) { // If the map is already assignable to the desired type return it, e.g. interfaces and // maps with the same key value types. if reflect.TypeOf(m.value).AssignableTo(typeDesc) { @@ -312,7 +312,7 @@ func (m *baseMap) Type() ref.Type { } // Value implements the ref.Val interface method. -func (m *baseMap) Value() interface{} { +func (m *baseMap) Value() any { return m.value } @@ -524,7 +524,7 @@ func (a *stringMapAccessor) Iterator() traits.Iterator { } } -func newStringIfaceMapAccessor(adapter ref.TypeAdapter, mapVal map[string]interface{}) mapAccessor { +func newStringIfaceMapAccessor(adapter ref.TypeAdapter, mapVal map[string]any) mapAccessor { return &stringIfaceMapAccessor{ TypeAdapter: adapter, mapVal: mapVal, @@ -533,7 +533,7 @@ func newStringIfaceMapAccessor(adapter ref.TypeAdapter, mapVal map[string]interf type stringIfaceMapAccessor struct { ref.TypeAdapter - mapVal map[string]interface{} + mapVal map[string]any } // Find uses native map accesses to find the key, returning (value, true) if present. @@ -582,7 +582,7 @@ func (m *protoMap) Contains(key ref.Val) ref.Val { // ConvertToNative implements the ref.Val interface method. // // Note, assignment to Golang struct types is not yet supported. -func (m *protoMap) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { +func (m *protoMap) ConvertToNative(typeDesc reflect.Type) (any, error) { // If the map is already assignable to the desired type return it, e.g. interfaces and // maps with the same key value types. switch typeDesc { @@ -789,7 +789,7 @@ func (m *protoMap) Type() ref.Type { } // Value implements the ref.Val interface method. -func (m *protoMap) Value() interface{} { +func (m *protoMap) Value() any { return m.value } diff --git a/common/types/map_test.go b/common/types/map_test.go index 0e257232..f8377cc1 100644 --- a/common/types/map_test.go +++ b/common/types/map_test.go @@ -44,7 +44,7 @@ type testStruct struct { func TestMapContains(t *testing.T) { reg := newTestRegistry(t, &proto3pb.TestAllTypes{}) - reflectMap := reg.NativeToValue(map[interface{}]interface{}{ + reflectMap := reg.NativeToValue(map[any]any{ int64(1): "hello", uint64(2): "world", }).(traits.Mapper) @@ -64,7 +64,7 @@ func TestMapContains(t *testing.T) { protoMap := pbMsg.Get(String("map_int64_nested_type")).(traits.Mapper) tests := []struct { - value interface{} + value any out Bool }{ {value: 1, out: True}, @@ -166,7 +166,7 @@ func TestDynamicMapConvertToNative_Json(t *testing.T) { func TestDynamicMapConvertToNative_Struct(t *testing.T) { reg := newTestRegistry(t) - mapVal := NewDynamicMap(reg, map[string]interface{}{ + mapVal := NewDynamicMap(reg, map[string]any{ "m": "hello", "details": []string{"world", "universe"}, }) @@ -182,7 +182,7 @@ func TestDynamicMapConvertToNative_Struct(t *testing.T) { func TestDynamicMapConvertToNative_StructPtr(t *testing.T) { reg := newTestRegistry(t) - mapVal := NewDynamicMap(reg, map[string]interface{}{ + mapVal := NewDynamicMap(reg, map[string]any{ "m": "hello", "details": []string{"world", "universe"}, }) @@ -198,7 +198,7 @@ func TestDynamicMapConvertToNative_StructPtr(t *testing.T) { func TestDynamicMapConvertToNative_StructPtrPtr(t *testing.T) { reg := newTestRegistry(t) - mapVal := NewDynamicMap(reg, map[string]interface{}{ + mapVal := NewDynamicMap(reg, map[string]any{ "m": "hello", "details": []string{"world", "universe"}, }) @@ -211,7 +211,7 @@ func TestDynamicMapConvertToNative_StructPtrPtr(t *testing.T) { func TestDynamicMapConvertToNative_Struct_InvalidFieldError(t *testing.T) { reg := newTestRegistry(t) - mapVal := NewDynamicMap(reg, map[string]interface{}{ + mapVal := NewDynamicMap(reg, map[string]any{ "m": "hello", "details": []string{"world", "universe"}, "invalid": "invalid field", @@ -224,7 +224,7 @@ func TestDynamicMapConvertToNative_Struct_InvalidFieldError(t *testing.T) { func TestDynamicMapConvertToNative_Struct_EmptyFieldError(t *testing.T) { reg := newTestRegistry(t) - mapVal := NewDynamicMap(reg, map[string]interface{}{ + mapVal := NewDynamicMap(reg, map[string]any{ "m": "hello", "details": []string{"world", "universe"}, "": "empty field", @@ -237,7 +237,7 @@ func TestDynamicMapConvertToNative_Struct_EmptyFieldError(t *testing.T) { func TestDynamicMapConvertToNative_Struct_PrivateFieldError(t *testing.T) { reg := newTestRegistry(t) - mapVal := NewDynamicMap(reg, map[string]interface{}{ + mapVal := NewDynamicMap(reg, map[string]any{ "message": "hello", "details": []string{"world", "universe"}, "private": "private field", @@ -278,12 +278,12 @@ func TestStringMapConvertToNative(t *testing.T) { t.Fatalf("protojson.Marshal() failed: %v", err) } jsonTxt := string(jsonBytes) - outMap := map[string]interface{}{} + outMap := map[string]any{} err = json.Unmarshal(jsonBytes, &outMap) if err != nil { t.Fatalf("json.Unmarshal(%q) failed: %v", jsonTxt, err) } - if !reflect.DeepEqual(outMap, map[string]interface{}{ + if !reflect.DeepEqual(outMap, map[string]any{ "first": "hello", "second": "world", }) { @@ -407,7 +407,7 @@ func TestStringMapEqual_NotTrue(t *testing.T) { if mapVal.Equal(other) != False { t.Error("mapVal.Equal(other) between maps with different keys did not return false") } - other = NewDynamicMap(reg, map[string]interface{}{ + other = NewDynamicMap(reg, map[string]any{ "first": "hello", "second": 1}) if IsError(mapVal.Equal(other)) { @@ -452,9 +452,9 @@ func TestDynamicMapGet(t *testing.T) { func TestStringIfaceMapGet(t *testing.T) { reg := newTestRegistry(t) - mapVal := NewStringInterfaceMap(reg, map[string]interface{}{ + mapVal := NewStringInterfaceMap(reg, map[string]any{ "nested": map[int32]float64{1: -1.0, 2: 2.0}, - "empty": map[string]interface{}{}, + "empty": map[string]any{}, }) nestedVal, ok := mapVal.Get(String("nested")).(traits.Mapper) if !ok { @@ -551,7 +551,7 @@ func TestMapIsZeroValue(t *testing.T) { obj := reg.NativeToValue(msg).(traits.Indexer) tests := []struct { - val interface{} + val any isZeroValue bool }{ { @@ -559,7 +559,7 @@ func TestMapIsZeroValue(t *testing.T) { isZeroValue: true, }, { - val: map[string]interface{}{}, + val: map[string]any{}, isZeroValue: true, }, { @@ -583,7 +583,7 @@ func TestMapIsZeroValue(t *testing.T) { isZeroValue: false, }, { - val: map[string]interface{}{"hello": []interface{}{}}, + val: map[string]any{"hello": []any{}}, isZeroValue: false, }, { @@ -629,7 +629,7 @@ func TestDynamicMapIterator(t *testing.T) { "empty": {}}) it := mapVal.Iterator() var i = 0 - var fieldNames []interface{} + var fieldNames []any for ; it.HasNext() == True; i++ { fieldName := it.Next() if value := mapVal.Get(fieldName); IsError(value) { @@ -653,7 +653,7 @@ func TestStringMapIterator(t *testing.T) { "second": "world"}) it := mapVal.Iterator() var i = 0 - var fieldNames []interface{} + var fieldNames []any for ; it.HasNext() == True; i++ { fieldName := it.Next() if value := mapVal.Get(fieldName); IsError(value) { @@ -863,11 +863,11 @@ func TestProtoMapConvertToNative(t *testing.T) { if !ok { t.Fatalf("obj.Get('map_string_string') did not return map: (%T)%v", field, field) } - convMap, err := mapVal.ConvertToNative(reflect.TypeOf(map[string]interface{}{})) + convMap, err := mapVal.ConvertToNative(reflect.TypeOf(map[string]any{})) if err != nil { t.Fatalf("mapVal.ConvertToNative() failed: %v", err) } - for k, v := range convMap.(map[string]interface{}) { + for k, v := range convMap.(map[string]any) { if strMap[k] != v { t.Errorf("got differing values for key %q: got %v, wanted: %v", k, strMap[k], v) } @@ -947,11 +947,11 @@ func TestProtoMapConvertToNative_NestedProto(t *testing.T) { if !ok { t.Fatalf("obj.Get('map_int64_nested_type') did not return map: (%T)%v", field, field) } - convMap, err := mapVal.ConvertToNative(reflect.TypeOf(map[int32]interface{}{})) + convMap, err := mapVal.ConvertToNative(reflect.TypeOf(map[int32]any{})) if err != nil { t.Fatalf("mapVal.ConvertToNative() failed: %v", err) } - for k, v := range convMap.(map[int32]interface{}) { + for k, v := range convMap.(map[int32]any) { if !proto.Equal(nestedTypeMap[int64(k)], v.(proto.Message)) { t.Errorf("got differing values for key %q: got %v, wanted: %v", k, nestedTypeMap[int64(k)], v) } diff --git a/common/types/null.go b/common/types/null.go index 45c77562..cce6b0c0 100644 --- a/common/types/null.go +++ b/common/types/null.go @@ -37,7 +37,7 @@ var ( ) // ConvertToNative implements ref.Val.ConvertToNative. -func (n Null) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { +func (n Null) ConvertToNative(typeDesc reflect.Type) (any, error) { switch typeDesc.Kind() { case reflect.Int32: return reflect.ValueOf(n).Convert(typeDesc).Interface(), nil @@ -96,6 +96,6 @@ func (n Null) Type() ref.Type { } // Value implements ref.Val.Value. -func (n Null) Value() interface{} { +func (n Null) Value() any { return structpb.NullValue_NULL_VALUE } diff --git a/common/types/object.go b/common/types/object.go index 05813a24..9955e2dc 100644 --- a/common/types/object.go +++ b/common/types/object.go @@ -53,7 +53,7 @@ func NewObject(adapter ref.TypeAdapter, typeValue: typeValue} } -func (o *protoObj) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { +func (o *protoObj) ConvertToNative(typeDesc reflect.Type) (any, error) { srcPB := o.value if reflect.TypeOf(srcPB).AssignableTo(typeDesc) { return srcPB, nil @@ -160,6 +160,6 @@ func (o *protoObj) Type() ref.Type { return o.typeValue } -func (o *protoObj) Value() interface{} { +func (o *protoObj) Value() any { return o.value } diff --git a/common/types/object_test.go b/common/types/object_test.go index 88e30941..85b06a8c 100644 --- a/common/types/object_test.go +++ b/common/types/object_test.go @@ -106,14 +106,14 @@ func TestProtoObjectConvertToNative(t *testing.T) { if err != nil { t.Fatalf("protojson.Marshal(%v) failed: %v", jsonVal, err) } - outMap := map[string]interface{}{} + outMap := map[string]any{} err = json.Unmarshal(jsonBytes, &outMap) if err != nil { t.Fatalf("json.Unmarshal(%q) failed: %v", jsonTxt, err) } - want := map[string]interface{}{ - "sourceInfo": map[string]interface{}{ - "lineOffsets": []interface{}{1.0, 2.0, 3.0}, + want := map[string]any{ + "sourceInfo": map[string]any{ + "lineOffsets": []any{1.0, 2.0, 3.0}, }, } if !reflect.DeepEqual(outMap, want) { diff --git a/common/types/optional.go b/common/types/optional.go index 75a0c141..880c07ff 100644 --- a/common/types/optional.go +++ b/common/types/optional.go @@ -53,7 +53,7 @@ func (o *Optional) GetValue() ref.Val { } // ConvertToNative implements the ref.Val interface method. -func (o *Optional) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { +func (o *Optional) ConvertToNative(typeDesc reflect.Type) (any, error) { if !o.HasValue() { return nil, errors.New("optional.none() dereference") } @@ -92,7 +92,7 @@ func (o *Optional) Type() ref.Type { } // Value returns the underlying 'Value()' of the wrapped value, if present. -func (o *Optional) Value() interface{} { +func (o *Optional) Value() any { if o.value == nil { return nil } diff --git a/common/types/pb/type.go b/common/types/pb/type.go index 912076fa..a50e45c4 100644 --- a/common/types/pb/type.go +++ b/common/types/pb/type.go @@ -87,7 +87,7 @@ func (td *TypeDescription) FieldByName(name string) (*FieldDescription, bool) { // MaybeUnwrap accepts a proto message as input and unwraps it to a primitive CEL type if possible. // // This method returns the unwrapped value and 'true', else the original value and 'false'. -func (td *TypeDescription) MaybeUnwrap(msg proto.Message) (interface{}, bool, error) { +func (td *TypeDescription) MaybeUnwrap(msg proto.Message) (any, bool, error) { return unwrap(td, msg) } @@ -195,7 +195,7 @@ func (fd *FieldDescription) Descriptor() protoreflect.FieldDescriptor { // // This function implements the FieldType.IsSet function contract which can be used to operate on // more than just protobuf field accesses; however, the target here must be a protobuf.Message. -func (fd *FieldDescription) IsSet(target interface{}) bool { +func (fd *FieldDescription) IsSet(target any) bool { switch v := target.(type) { case proto.Message: pbRef := v.ProtoReflect() @@ -219,14 +219,14 @@ func (fd *FieldDescription) IsSet(target interface{}) bool { // // This function implements the FieldType.GetFrom function contract which can be used to operate // on more than just protobuf field accesses; however, the target here must be a protobuf.Message. -func (fd *FieldDescription) GetFrom(target interface{}) (interface{}, error) { +func (fd *FieldDescription) GetFrom(target any) (any, error) { v, ok := target.(proto.Message) if !ok { return nil, fmt.Errorf("unsupported field selection target: (%T)%v", target, target) } pbRef := v.ProtoReflect() pbDesc := pbRef.Descriptor() - var fieldVal interface{} + var fieldVal any if pbDesc == fd.desc.ContainingMessage() { // When the target protobuf shares the same message descriptor instance as the field // descriptor, use the cached field descriptor value. @@ -289,7 +289,7 @@ func (fd *FieldDescription) IsList() bool { // // This function returns the unwrapped value and 'true' on success, or the original value // and 'false' otherwise. -func (fd *FieldDescription) MaybeUnwrapDynamic(msg protoreflect.Message) (interface{}, bool, error) { +func (fd *FieldDescription) MaybeUnwrapDynamic(msg protoreflect.Message) (any, bool, error) { return unwrapDynamic(fd, msg) } @@ -362,7 +362,7 @@ func checkedWrap(t *exprpb.Type) *exprpb.Type { // input message is a *dynamicpb.Message which obscures the typing information from Go. // // Returns the unwrapped value and 'true' if unwrapped, otherwise the input value and 'false'. -func unwrap(desc description, msg proto.Message) (interface{}, bool, error) { +func unwrap(desc description, msg proto.Message) (any, bool, error) { switch v := msg.(type) { case *anypb.Any: dynMsg, err := v.UnmarshalNew() @@ -418,7 +418,7 @@ func unwrap(desc description, msg proto.Message) (interface{}, bool, error) { // unwrapDynamic unwraps a reflected protobuf Message value. // // Returns the unwrapped value and 'true' if unwrapped, otherwise the input value and 'false'. -func unwrapDynamic(desc description, refMsg protoreflect.Message) (interface{}, bool, error) { +func unwrapDynamic(desc description, refMsg protoreflect.Message) (any, bool, error) { msg := refMsg.Interface() if !refMsg.IsValid() { msg = desc.Zero() @@ -508,7 +508,7 @@ func unwrapDynamic(desc description, refMsg protoreflect.Message) (interface{}, // reflectTypeOf intercepts the reflect.Type call to ensure that dynamicpb.Message types preserve // well-known protobuf reflected types expected by the CEL type system. -func reflectTypeOf(val interface{}) reflect.Type { +func reflectTypeOf(val any) reflect.Type { switch v := val.(type) { case proto.Message: return reflect.TypeOf(zeroValueOf(v)) diff --git a/common/types/pb/type_test.go b/common/types/pb/type_test.go index 3261b149..5aa36cb1 100644 --- a/common/types/pb/type_test.go +++ b/common/types/pb/type_test.go @@ -159,7 +159,7 @@ func TestFieldDescriptionGetFrom(t *testing.T) { }, }, SingleValue: structpb.NewStringValue("hello world"), - SingleStruct: jsonStruct(t, map[string]interface{}{ + SingleStruct: jsonStruct(t, map[string]any{ "null": nil, }), } @@ -172,7 +172,7 @@ func TestFieldDescriptionGetFrom(t *testing.T) { if !found { t.Fatalf("pbdb.DescribeType(%q) not found", msgName) } - expected := map[string]interface{}{ + expected := map[string]any{ "single_uint64": uint64(12), "single_duration": time.Duration(1234), "single_timestamp": time.Unix(12345, 0).UTC(), @@ -184,7 +184,7 @@ func TestFieldDescriptionGetFrom(t *testing.T) { }, "standalone_enum": int64(1), "single_value": "hello world", - "single_struct": jsonStruct(t, map[string]interface{}{ + "single_struct": jsonStruct(t, map[string]any{ "null": nil, }), } @@ -224,7 +224,7 @@ func TestFieldDescriptionIsSet(t *testing.T) { } tests := []struct { - msg interface{} + msg any field string isSet bool }{ @@ -284,7 +284,7 @@ func TestTypeDescriptionMaybeUnwrap(t *testing.T) { tests := []struct { in proto.Message - out interface{} + out any }{ { in: msgDesc.Zero(), @@ -312,7 +312,7 @@ func TestTypeDescriptionMaybeUnwrap(t *testing.T) { }, { in: dynMsg(t, &structpb.ListValue{}), - out: jsonList(t, []interface{}{}), + out: jsonList(t, []any{}), }, { in: structpb.NewBoolValue(true), @@ -339,12 +339,12 @@ func TestTypeDescriptionMaybeUnwrap(t *testing.T) { out: "hello world", }, { - in: structpb.NewListValue(jsonList(t, []interface{}{true, 1.0})), - out: jsonList(t, []interface{}{true, 1.0}), + in: structpb.NewListValue(jsonList(t, []any{true, 1.0})), + out: jsonList(t, []any{true, 1.0}), }, { - in: structpb.NewStructValue(jsonStruct(t, map[string]interface{}{"hello": "world"})), - out: jsonStruct(t, map[string]interface{}{"hello": "world"}), + in: structpb.NewStructValue(jsonStruct(t, map[string]any{"hello": "world"})), + out: jsonStruct(t, map[string]any{"hello": "world"}), }, { in: wrapperspb.Bool(false), @@ -516,7 +516,7 @@ func anyMsg(t *testing.T, msg proto.Message) *anypb.Any { return pb } -func jsonList(t *testing.T, elems []interface{}) *structpb.ListValue { +func jsonList(t *testing.T, elems []any) *structpb.ListValue { t.Helper() l, err := structpb.NewList(elems) if err != nil { @@ -525,7 +525,7 @@ func jsonList(t *testing.T, elems []interface{}) *structpb.ListValue { return l } -func jsonStruct(t *testing.T, entries map[string]interface{}) *structpb.Struct { +func jsonStruct(t *testing.T, entries map[string]any) *structpb.Struct { t.Helper() s, err := structpb.NewStruct(entries) if err != nil { diff --git a/common/types/provider.go b/common/types/provider.go index 9ef8ce01..c8d68c12 100644 --- a/common/types/provider.go +++ b/common/types/provider.go @@ -196,7 +196,7 @@ func (p *protoTypeRegistry) RegisterType(types ...ref.Type) error { // providing support for custom proto-based types. // // This method should be the inverse of ref.Val.ConvertToNative. -func (p *protoTypeRegistry) NativeToValue(value interface{}) ref.Val { +func (p *protoTypeRegistry) NativeToValue(value any) ref.Val { if val, found := nativeToValue(p, value); found { return val } @@ -250,7 +250,7 @@ var ( ) // NativeToValue implements the ref.TypeAdapter interface. -func (a *defaultTypeAdapter) NativeToValue(value interface{}) ref.Val { +func (a *defaultTypeAdapter) NativeToValue(value any) ref.Val { if val, found := nativeToValue(a, value); found { return val } @@ -259,7 +259,7 @@ func (a *defaultTypeAdapter) NativeToValue(value interface{}) ref.Val { // nativeToValue returns the converted (ref.Val, true) of a conversion is found, // otherwise (nil, false) -func nativeToValue(a ref.TypeAdapter, value interface{}) (ref.Val, bool) { +func nativeToValue(a ref.TypeAdapter, value any) (ref.Val, bool) { switch v := value.(type) { case nil: return NullValue, true @@ -365,7 +365,7 @@ func nativeToValue(a ref.TypeAdapter, value interface{}) (ref.Val, bool) { // specializations for common map types. case map[string]string: return NewStringStringMap(a, v), true - case map[string]interface{}: + case map[string]any: return NewStringInterfaceMap(a, v), true case map[ref.Val]ref.Val: return NewRefValMap(a, v), true diff --git a/common/types/provider_test.go b/common/types/provider_test.go index d1fbdf40..7f596e00 100644 --- a/common/types/provider_test.go +++ b/common/types/provider_test.go @@ -204,32 +204,32 @@ func TestConvertToNative(t *testing.T) { // Core type conversion tests. expectValueToNative(t, True, true) expectValueToNative(t, True, True) - expectValueToNative(t, NewDynamicList(reg, []Bool{True, False}), []interface{}{true, false}) + expectValueToNative(t, NewDynamicList(reg, []Bool{True, False}), []any{true, false}) expectValueToNative(t, NewDynamicList(reg, []Bool{True, False}), []ref.Val{True, False}) expectValueToNative(t, Int(-1), int32(-1)) expectValueToNative(t, Int(2), int64(2)) expectValueToNative(t, Int(-1), Int(-1)) - expectValueToNative(t, NewDynamicList(reg, []Int{4}), []interface{}{int64(4)}) + expectValueToNative(t, NewDynamicList(reg, []Int{4}), []any{int64(4)}) expectValueToNative(t, NewDynamicList(reg, []Int{5}), []ref.Val{Int(5)}) expectValueToNative(t, Uint(3), uint32(3)) expectValueToNative(t, Uint(4), uint64(4)) expectValueToNative(t, Uint(5), Uint(5)) - expectValueToNative(t, NewDynamicList(reg, []Uint{4}), []interface{}{uint64(4)}) + expectValueToNative(t, NewDynamicList(reg, []Uint{4}), []any{uint64(4)}) expectValueToNative(t, NewDynamicList(reg, []Uint{5}), []ref.Val{Uint(5)}) expectValueToNative(t, Double(5.5), float32(5.5)) expectValueToNative(t, Double(-5.5), float64(-5.5)) - expectValueToNative(t, NewDynamicList(reg, []Double{-5.5}), []interface{}{-5.5}) + expectValueToNative(t, NewDynamicList(reg, []Double{-5.5}), []any{-5.5}) expectValueToNative(t, NewDynamicList(reg, []Double{-5.5}), []ref.Val{Double(-5.5)}) expectValueToNative(t, Double(-5.5), Double(-5.5)) expectValueToNative(t, String("hello"), "hello") expectValueToNative(t, String("hello"), String("hello")) expectValueToNative(t, NullValue, structpb.NullValue_NULL_VALUE) expectValueToNative(t, NullValue, NullValue) - expectValueToNative(t, NewDynamicList(reg, []Null{NullValue}), []interface{}{structpb.NullValue_NULL_VALUE}) + expectValueToNative(t, NewDynamicList(reg, []Null{NullValue}), []any{structpb.NullValue_NULL_VALUE}) expectValueToNative(t, NewDynamicList(reg, []Null{NullValue}), []ref.Val{NullValue}) expectValueToNative(t, Bytes("world"), []byte("world")) expectValueToNative(t, Bytes("world"), Bytes("world")) - expectValueToNative(t, NewDynamicList(reg, []Bytes{Bytes("hello")}), []interface{}{[]byte("hello")}) + expectValueToNative(t, NewDynamicList(reg, []Bytes{Bytes("hello")}), []any{[]byte("hello")}) expectValueToNative(t, NewDynamicList(reg, []Bytes{Bytes("hello")}), []ref.Val{Bytes("hello")}) expectValueToNative(t, NewDynamicList(reg, []int64{1, 2, 3}), []int32{1, 2, 3}) expectValueToNative(t, Duration{Duration: time.Duration(500)}, time.Duration(500)) @@ -457,7 +457,7 @@ func TestUnsupportedConversion(t *testing.T) { } } -func expectValueToNative(t *testing.T, in ref.Val, out interface{}) { +func expectValueToNative(t *testing.T, in ref.Val, out any) { t.Helper() if val, err := in.ConvertToNative(reflect.TypeOf(out)); err != nil { t.Error(err) @@ -480,7 +480,7 @@ func expectValueToNative(t *testing.T, in ref.Val, out interface{}) { } } -func expectNativeToValue(t *testing.T, in interface{}, out ref.Val) { +func expectNativeToValue(t *testing.T, in any, out ref.Val) { t.Helper() reg := newTestRegistry(t, &exprpb.ParsedExpr{}) if val := reg.NativeToValue(in); IsError(val) { @@ -498,7 +498,7 @@ func BenchmarkNativeToValue(b *testing.B) { if err != nil { b.Fatalf("NewRegistry() failed: %v", err) } - inputs := []interface{}{ + inputs := []any{ true, false, float32(-1.2), diff --git a/common/types/ref/provider.go b/common/types/ref/provider.go index 91a711fa..9ce2e34b 100644 --- a/common/types/ref/provider.go +++ b/common/types/ref/provider.go @@ -55,7 +55,7 @@ type TypeProvider interface { // TypeAdapter converts native Go values of varying type and complexity to equivalent CEL values. type TypeAdapter interface { // NativeToValue converts the input `value` to a CEL `ref.Val`. - NativeToValue(value interface{}) Val + NativeToValue(value any) Val } // TypeRegistry allows third-parties to add custom types to CEL. Not all `TypeProvider` @@ -97,7 +97,7 @@ type FieldType struct { } // FieldTester is used to test field presence on an input object. -type FieldTester func(target interface{}) bool +type FieldTester func(target any) bool // FieldGetter is used to get the field value from an input object, if set. -type FieldGetter func(target interface{}) (interface{}, error) +type FieldGetter func(target any) (any, error) diff --git a/common/types/ref/reference.go b/common/types/ref/reference.go index 3098580c..5921ffd8 100644 --- a/common/types/ref/reference.go +++ b/common/types/ref/reference.go @@ -37,7 +37,7 @@ type Type interface { type Val interface { // ConvertToNative converts the Value to a native Go struct according to the // reflected type description, or error if the conversion is not feasible. - ConvertToNative(typeDesc reflect.Type) (interface{}, error) + ConvertToNative(typeDesc reflect.Type) (any, error) // ConvertToType supports type conversions between value types supported by the expression language. ConvertToType(typeValue Type) Val @@ -50,5 +50,5 @@ type Val interface { // Value returns the raw value of the instance which may not be directly compatible with the expression // language types. - Value() interface{} + Value() any } diff --git a/common/types/string.go b/common/types/string.go index bf9aa0fa..a65cc14e 100644 --- a/common/types/string.go +++ b/common/types/string.go @@ -72,7 +72,7 @@ func (s String) Compare(other ref.Val) ref.Val { } // ConvertToNative implements ref.Val.ConvertToNative. -func (s String) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { +func (s String) ConvertToNative(typeDesc reflect.Type) (any, error) { switch typeDesc.Kind() { case reflect.String: if reflect.TypeOf(s).AssignableTo(typeDesc) { @@ -194,7 +194,7 @@ func (s String) Type() ref.Type { } // Value implements ref.Val.Value. -func (s String) Value() interface{} { +func (s String) Value() any { return string(s) } diff --git a/common/types/timestamp.go b/common/types/timestamp.go index 17af0d6b..2947cecf 100644 --- a/common/types/timestamp.go +++ b/common/types/timestamp.go @@ -89,7 +89,7 @@ func (t Timestamp) Compare(other ref.Val) ref.Val { } // ConvertToNative implements ref.Val.ConvertToNative. -func (t Timestamp) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { +func (t Timestamp) ConvertToNative(typeDesc reflect.Type) (any, error) { // If the timestamp is already assignable to the desired type return it. if reflect.TypeOf(t.Time).AssignableTo(typeDesc) { return t.Time, nil @@ -185,7 +185,7 @@ func (t Timestamp) Type() ref.Type { } // Value implements ref.Val.Value. -func (t Timestamp) Value() interface{} { +func (t Timestamp) Value() any { return t.Time } diff --git a/common/types/timestamp_test.go b/common/types/timestamp_test.go index 1a5f2510..cd7d996f 100644 --- a/common/types/timestamp_test.go +++ b/common/types/timestamp_test.go @@ -59,7 +59,7 @@ func TestTimestampOperators(t *testing.T) { tests := []struct { name string op func() ref.Val - out interface{} + out any }{ // Addition tests. { @@ -272,7 +272,7 @@ func TestTimestampConvertToNative(t *testing.T) { if err != nil { t.Error(err) } - var want interface{} + var want any want = tpb.New(ts.Time) if !proto.Equal(val.(proto.Message), want.(proto.Message)) { t.Errorf("Got '%v', expected '%v'", val, want) diff --git a/common/types/type.go b/common/types/type.go index 21160974..164a4605 100644 --- a/common/types/type.go +++ b/common/types/type.go @@ -53,7 +53,7 @@ func NewObjectTypeValue(name string) *TypeValue { } // ConvertToNative implements ref.Val.ConvertToNative. -func (t *TypeValue) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { +func (t *TypeValue) ConvertToNative(typeDesc reflect.Type) (any, error) { // TODO: replace the internal type representation with a proto-value. return nil, fmt.Errorf("type conversion not supported for 'type'") } @@ -97,6 +97,6 @@ func (t *TypeValue) TypeName() string { } // Value implements ref.Val.Value. -func (t *TypeValue) Value() interface{} { +func (t *TypeValue) Value() any { return t.name } diff --git a/common/types/uint.go b/common/types/uint.go index 135661b8..988e6f1a 100644 --- a/common/types/uint.go +++ b/common/types/uint.go @@ -82,7 +82,7 @@ func (i Uint) Compare(other ref.Val) ref.Val { } // ConvertToNative implements ref.Val.ConvertToNative. -func (i Uint) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { +func (i Uint) ConvertToNative(typeDesc reflect.Type) (any, error) { switch typeDesc.Kind() { case reflect.Uint, reflect.Uint32: v, err := uint64ToUint32Checked(uint64(i)) @@ -244,7 +244,7 @@ func (i Uint) Type() ref.Type { } // Value implements ref.Val.Value. -func (i Uint) Value() interface{} { +func (i Uint) Value() any { return uint64(i) } diff --git a/common/types/uint_test.go b/common/types/uint_test.go index ecc1fe8c..777d7955 100644 --- a/common/types/uint_test.go +++ b/common/types/uint_test.go @@ -233,7 +233,7 @@ func TestUintConvertToType(t *testing.T) { name string in uint64 toType ref.Type - out interface{} + out any }{ { name: "UintToUint", diff --git a/common/types/unknown.go b/common/types/unknown.go index 95b47426..bc411c15 100644 --- a/common/types/unknown.go +++ b/common/types/unknown.go @@ -30,7 +30,7 @@ var ( ) // ConvertToNative implements ref.Val.ConvertToNative. -func (u Unknown) ConvertToNative(typeDesc reflect.Type) (interface{}, error) { +func (u Unknown) ConvertToNative(typeDesc reflect.Type) (any, error) { return u.Value(), nil } @@ -50,7 +50,7 @@ func (u Unknown) Type() ref.Type { } // Value implements ref.Val.Value. -func (u Unknown) Value() interface{} { +func (u Unknown) Value() any { return []int64(u) } diff --git a/examples/custom_global_function_test.go b/examples/custom_global_function_test.go index ac4c6934..f4d44fd1 100644 --- a/examples/custom_global_function_test.go +++ b/examples/custom_global_function_test.go @@ -52,7 +52,7 @@ func ExampleCustomGlobalFunction() { log.Fatalf("Program creation error: %v\n", err) } - out, _, err := prg.Eval(map[string]interface{}{ + out, _, err := prg.Eval(map[string]any{ "i": "CEL", "you": "world", }) diff --git a/examples/custom_instance_function_test.go b/examples/custom_instance_function_test.go index 661a55a8..8faf1d71 100644 --- a/examples/custom_instance_function_test.go +++ b/examples/custom_instance_function_test.go @@ -38,7 +38,7 @@ func ExampleCustomInstanceFunction() { log.Fatalf("Program creation error: %v\n", err) } - out, _, err := prg.Eval(map[string]interface{}{ + out, _, err := prg.Eval(map[string]any{ "i": "CEL", "you": "world", }) diff --git a/examples/simple_test.go b/examples/simple_test.go index 61fa39c1..f4401ed4 100644 --- a/examples/simple_test.go +++ b/examples/simple_test.go @@ -35,7 +35,7 @@ func ExampleSimple() { if err != nil { log.Fatalln(err) } - out, _, err := prg.Eval(map[string]interface{}{ + out, _, err := prg.Eval(map[string]any{ "name": "CEL", }) if err != nil { diff --git a/interpreter/activation.go b/interpreter/activation.go index 8686d4f0..f82e4e90 100644 --- a/interpreter/activation.go +++ b/interpreter/activation.go @@ -28,7 +28,7 @@ import ( type Activation interface { // ResolveName returns a value from the activation by qualified name, or false if the name // could not be found. - ResolveName(name string) (interface{}, bool) + ResolveName(name string) (any, bool) // Parent returns the parent of the current activation, may be nil. // If non-nil, the parent will be searched during resolve calls. @@ -43,23 +43,23 @@ func EmptyActivation() Activation { // emptyActivation is a variable-free activation. type emptyActivation struct{} -func (emptyActivation) ResolveName(string) (interface{}, bool) { return nil, false } -func (emptyActivation) Parent() Activation { return nil } +func (emptyActivation) ResolveName(string) (any, bool) { return nil, false } +func (emptyActivation) Parent() Activation { return nil } // NewActivation returns an activation based on a map-based binding where the map keys are // expected to be qualified names used with ResolveName calls. // -// The input `bindings` may either be of type `Activation` or `map[string]interface{}`. +// The input `bindings` may either be of type `Activation` or `map[string]any`. // // Lazy bindings may be supplied within the map-based input in either of the following forms: -// - func() interface{} +// - func() any // - func() ref.Val // // The output of the lazy binding will overwrite the variable reference in the internal map. // // Values which are not represented as ref.Val types on input may be adapted to a ref.Val using // the ref.TypeAdapter configured in the environment. -func NewActivation(bindings interface{}) (Activation, error) { +func NewActivation(bindings any) (Activation, error) { if bindings == nil { return nil, errors.New("bindings must be non-nil") } @@ -67,7 +67,7 @@ func NewActivation(bindings interface{}) (Activation, error) { if isActivation { return a, nil } - m, isMap := bindings.(map[string]interface{}) + m, isMap := bindings.(map[string]any) if !isMap { return nil, fmt.Errorf( "activation input must be an activation or map[string]interface: got %T", @@ -81,7 +81,7 @@ func NewActivation(bindings interface{}) (Activation, error) { // Named bindings may lazily supply values by providing a function which accepts no arguments and // produces an interface value. type mapActivation struct { - bindings map[string]interface{} + bindings map[string]any } // Parent implements the Activation interface method. @@ -90,7 +90,7 @@ func (a *mapActivation) Parent() Activation { } // ResolveName implements the Activation interface method. -func (a *mapActivation) ResolveName(name string) (interface{}, bool) { +func (a *mapActivation) ResolveName(name string) (any, bool) { obj, found := a.bindings[name] if !found { return nil, false @@ -100,7 +100,7 @@ func (a *mapActivation) ResolveName(name string) (interface{}, bool) { obj = fn() a.bindings[name] = obj } - fnRaw, isLazy := obj.(func() interface{}) + fnRaw, isLazy := obj.(func() any) if isLazy { obj = fnRaw() a.bindings[name] = obj @@ -121,7 +121,7 @@ func (a *hierarchicalActivation) Parent() Activation { } // ResolveName implements the Activation interface method. -func (a *hierarchicalActivation) ResolveName(name string) (interface{}, bool) { +func (a *hierarchicalActivation) ResolveName(name string) (any, bool) { if object, found := a.child.ResolveName(name); found { return object, found } @@ -138,8 +138,8 @@ func NewHierarchicalActivation(parent Activation, child Activation) Activation { // representing field and index operations that should result in a 'types.Unknown' result. // // The `bindings` value may be any value type supported by the interpreter.NewActivation call, -// but is typically either an existing Activation or map[string]interface{}. -func NewPartialActivation(bindings interface{}, +// but is typically either an existing Activation or map[string]any. +func NewPartialActivation(bindings any, unknowns ...*AttributePattern) (PartialActivation, error) { a, err := NewActivation(bindings) if err != nil { @@ -184,7 +184,7 @@ func (v *varActivation) Parent() Activation { } // ResolveName implements the Activation interface method. -func (v *varActivation) ResolveName(name string) (interface{}, bool) { +func (v *varActivation) ResolveName(name string) (any, bool) { if name == v.name { return v.val, true } @@ -194,7 +194,7 @@ func (v *varActivation) ResolveName(name string) (interface{}, bool) { var ( // pool of var activations to reduce allocations during folds. varActivationPool = &sync.Pool{ - New: func() interface{} { + New: func() any { return &varActivation{} }, } diff --git a/interpreter/activation_test.go b/interpreter/activation_test.go index 7c7249a7..fab4e433 100644 --- a/interpreter/activation_test.go +++ b/interpreter/activation_test.go @@ -23,7 +23,7 @@ import ( ) func TestActivation(t *testing.T) { - act, err := NewActivation(map[string]interface{}{"a": types.True}) + act, err := NewActivation(map[string]any{"a": types.True}) if err != nil { t.Fatalf("Got err: %v, wanted activation", err) } @@ -38,7 +38,7 @@ func TestActivation(t *testing.T) { } func TestActivation_Resolve(t *testing.T) { - activation, _ := NewActivation(map[string]interface{}{"a": types.True}) + activation, _ := NewActivation(map[string]any{"a": types.True}) if val, found := activation.ResolveName("a"); !found || val != types.True { t.Error("Activation failed to resolve 'a'") } @@ -52,7 +52,7 @@ func TestActivation_ResolveLazy(t *testing.T) { } return v } - a, _ := NewActivation(map[string]interface{}{ + a, _ := NewActivation(map[string]any{ "now": now, }) first, _ := a.ResolveName("now") @@ -65,12 +65,12 @@ func TestActivation_ResolveLazy(t *testing.T) { func TestHierarchicalActivation(t *testing.T) { // compose a parent with more properties than the child - parent, _ := NewActivation(map[string]interface{}{ + parent, _ := NewActivation(map[string]any{ "a": types.String("world"), "b": types.Int(-42), }) // compose the child such that it shadows the parent - child, _ := NewActivation(map[string]interface{}{ + child, _ := NewActivation(map[string]any{ "a": types.True, "c": types.String("universe"), }) diff --git a/interpreter/attribute_patterns.go b/interpreter/attribute_patterns.go index b33f7f7f..ad9a909f 100644 --- a/interpreter/attribute_patterns.go +++ b/interpreter/attribute_patterns.go @@ -36,9 +36,9 @@ import ( // // Examples: // -// 1. ns.myvar["complex-value"] -// 2. ns.myvar["complex-value"][0] -// 3. ns.myvar["complex-value"].*.name +// 1. ns.myvar["complex-value"] +// 2. ns.myvar["complex-value"][0] +// 3. ns.myvar["complex-value"].*.name // // The first example is simple: match an attribute where the variable is 'ns.myvar' with a // field access on 'complex-value'. The second example expands the match to indicate that only @@ -108,7 +108,7 @@ func (apat *AttributePattern) QualifierPatterns() []*AttributeQualifierPattern { // AttributeQualifierPattern holds a wildcard or valued qualifier pattern. type AttributeQualifierPattern struct { wildcard bool - value interface{} + value any } // Matches returns true if the qualifier pattern is a wildcard, or the Qualifier implements the @@ -134,44 +134,44 @@ func (qpat *AttributeQualifierPattern) Matches(q Qualifier) bool { type qualifierValueEquator interface { // QualifierValueEquals returns true if the input value is equal to the value held in the // Qualifier. - QualifierValueEquals(value interface{}) bool + QualifierValueEquals(value any) bool } // QualifierValueEquals implementation for boolean qualifiers. -func (q *boolQualifier) QualifierValueEquals(value interface{}) bool { +func (q *boolQualifier) QualifierValueEquals(value any) bool { bval, ok := value.(bool) return ok && q.value == bval } // QualifierValueEquals implementation for field qualifiers. -func (q *fieldQualifier) QualifierValueEquals(value interface{}) bool { +func (q *fieldQualifier) QualifierValueEquals(value any) bool { sval, ok := value.(string) return ok && q.Name == sval } // QualifierValueEquals implementation for string qualifiers. -func (q *stringQualifier) QualifierValueEquals(value interface{}) bool { +func (q *stringQualifier) QualifierValueEquals(value any) bool { sval, ok := value.(string) return ok && q.value == sval } // QualifierValueEquals implementation for int qualifiers. -func (q *intQualifier) QualifierValueEquals(value interface{}) bool { +func (q *intQualifier) QualifierValueEquals(value any) bool { return numericValueEquals(value, q.celValue) } // QualifierValueEquals implementation for uint qualifiers. -func (q *uintQualifier) QualifierValueEquals(value interface{}) bool { +func (q *uintQualifier) QualifierValueEquals(value any) bool { return numericValueEquals(value, q.celValue) } // QualifierValueEquals implementation for double qualifiers. -func (q *doubleQualifier) QualifierValueEquals(value interface{}) bool { +func (q *doubleQualifier) QualifierValueEquals(value any) bool { return numericValueEquals(value, q.celValue) } // numericValueEquals uses CEL equality to determine whether two number values are -func numericValueEquals(value interface{}, celValue ref.Val) bool { +func numericValueEquals(value any, celValue ref.Val) bool { val := types.DefaultTypeAdapter.NativeToValue(value) return celValue.Equal(val) == types.True } @@ -341,7 +341,7 @@ func (m *attributeMatcher) AddQualifier(qual Qualifier) (Attribute, error) { // Resolve is an implementation of the Attribute interface method which uses the // attributeMatcher TryResolve implementation rather than the embedded NamespacedAttribute // Resolve implementation. -func (m *attributeMatcher) Resolve(vars Activation) (interface{}, error) { +func (m *attributeMatcher) Resolve(vars Activation) (any, error) { obj, found, err := m.TryResolve(vars) if err != nil { return nil, err @@ -355,7 +355,7 @@ func (m *attributeMatcher) Resolve(vars Activation) (interface{}, error) { // TryResolve is an implementation of the NamespacedAttribute interface method which tests // for matching unknown attribute patterns and returns types.Unknown if present. Otherwise, // the standard Resolve logic applies. -func (m *attributeMatcher) TryResolve(vars Activation) (interface{}, bool, error) { +func (m *attributeMatcher) TryResolve(vars Activation) (any, bool, error) { id := m.NamespacedAttribute.ID() // Bug in how partial activation is resolved, should search parents as well. partial, isPartial := toPartialActivation(vars) @@ -376,7 +376,7 @@ func (m *attributeMatcher) TryResolve(vars Activation) (interface{}, bool, error } // Qualify is an implementation of the Qualifier interface method. -func (m *attributeMatcher) Qualify(vars Activation, obj interface{}) (interface{}, error) { +func (m *attributeMatcher) Qualify(vars Activation, obj any) (any, error) { val, err := m.Resolve(vars) if err != nil { return nil, err diff --git a/interpreter/attribute_patterns_test.go b/interpreter/attribute_patterns_test.go index e87b18cd..10bb849d 100644 --- a/interpreter/attribute_patterns_test.go +++ b/interpreter/attribute_patterns_test.go @@ -36,7 +36,7 @@ type attr struct { // variable name, fully qualified unless the attr is marked as unchecked=true name string // quals contains a list of static qualifiers. - quals []interface{} + quals []any } // patternTest describes a pattern, and a set of matches and misses for the pattern to highlight @@ -52,7 +52,7 @@ var patternTests = map[string]patternTest{ pattern: NewAttributePattern("var"), matches: []attr{ {name: "var"}, - {name: "var", quals: []interface{}{"field"}}, + {name: "var", quals: []any{"field"}}, }, misses: []attr{ {name: "ns.var"}, @@ -62,10 +62,10 @@ var patternTests = map[string]patternTest{ pattern: NewAttributePattern("ns.app.var"), matches: []attr{ {name: "ns.app.var"}, - {name: "ns.app.var", quals: []interface{}{int64(0)}}, + {name: "ns.app.var", quals: []any{int64(0)}}, { name: "ns", - quals: []interface{}{"app", "var", "foo"}, + quals: []any{"app", "var", "foo"}, container: "ns.app", unchecked: true, }, @@ -74,7 +74,7 @@ var patternTests = map[string]patternTest{ {name: "ns.var"}, { name: "ns", - quals: []interface{}{"var"}, + quals: []any{"var"}, container: "ns.app", unchecked: true, }, @@ -84,48 +84,48 @@ var patternTests = map[string]patternTest{ pattern: NewAttributePattern("var").QualString("field"), matches: []attr{ {name: "var"}, - {name: "var", quals: []interface{}{"field"}}, - {name: "var", quals: []interface{}{"field"}, unchecked: true}, - {name: "var", quals: []interface{}{"field", uint64(1)}}, + {name: "var", quals: []any{"field"}}, + {name: "var", quals: []any{"field"}, unchecked: true}, + {name: "var", quals: []any{"field", uint64(1)}}, }, misses: []attr{ - {name: "var", quals: []interface{}{"other"}}, + {name: "var", quals: []any{"other"}}, }, }, "var_index": { pattern: NewAttributePattern("var").QualInt(0), matches: []attr{ {name: "var"}, - {name: "var", quals: []interface{}{int64(0)}}, - {name: "var", quals: []interface{}{float64(0)}}, - {name: "var", quals: []interface{}{int64(0), false}}, - {name: "var", quals: []interface{}{uint64(0)}}, + {name: "var", quals: []any{int64(0)}}, + {name: "var", quals: []any{float64(0)}}, + {name: "var", quals: []any{int64(0), false}}, + {name: "var", quals: []any{uint64(0)}}, }, misses: []attr{ - {name: "var", quals: []interface{}{int64(1), false}}, + {name: "var", quals: []any{int64(1), false}}, }, }, "var_index_uint": { pattern: NewAttributePattern("var").QualUint(1), matches: []attr{ {name: "var"}, - {name: "var", quals: []interface{}{uint64(1)}}, - {name: "var", quals: []interface{}{uint64(1), true}}, - {name: "var", quals: []interface{}{int64(1), false}}, + {name: "var", quals: []any{uint64(1)}}, + {name: "var", quals: []any{uint64(1), true}}, + {name: "var", quals: []any{int64(1), false}}, }, misses: []attr{ - {name: "var", quals: []interface{}{uint64(0)}}, + {name: "var", quals: []any{uint64(0)}}, }, }, "var_index_bool": { pattern: NewAttributePattern("var").QualBool(true), matches: []attr{ {name: "var"}, - {name: "var", quals: []interface{}{true}}, - {name: "var", quals: []interface{}{true, "name"}}, + {name: "var", quals: []any{true}}, + {name: "var", quals: []any{true, "name"}}, }, misses: []attr{ - {name: "var", quals: []interface{}{false}}, + {name: "var", quals: []any{false}}, {name: "none"}, }, }, @@ -137,25 +137,25 @@ var patternTests = map[string]patternTest{ // when testing variable names. { name: "var", - quals: []interface{}{true}, + quals: []any{true}, container: "ns", unchecked: true, }, { name: "var", - quals: []interface{}{"name"}, + quals: []any{"name"}, container: "ns", unchecked: true, }, { name: "var", - quals: []interface{}{"name"}, + quals: []any{"name"}, container: "ns", unchecked: true, }, }, misses: []attr{ - {name: "var", quals: []interface{}{false}}, + {name: "var", quals: []any{false}}, {name: "none"}, }, }, @@ -163,19 +163,19 @@ var patternTests = map[string]patternTest{ pattern: NewAttributePattern("var").Wildcard().QualString("field"), matches: []attr{ {name: "var"}, - {name: "var", quals: []interface{}{true}}, - {name: "var", quals: []interface{}{int64(10), "field"}}, + {name: "var", quals: []any{true}}, + {name: "var", quals: []any{int64(10), "field"}}, }, misses: []attr{ - {name: "var", quals: []interface{}{int64(10), "other"}}, + {name: "var", quals: []any{int64(10), "other"}}, }, }, "var_wildcard_wildcard": { pattern: NewAttributePattern("var").Wildcard().Wildcard(), matches: []attr{ {name: "var"}, - {name: "var", quals: []interface{}{true}}, - {name: "var", quals: []interface{}{int64(10), "field"}}, + {name: "var", quals: []any{true}}, + {name: "var", quals: []any{int64(10), "field"}}, }, misses: []attr{ {name: "none"}, @@ -246,7 +246,7 @@ func TestAttributePattern_CrossReference(t *testing.T) { // Ensure that var a[b], the dynamic index into var 'a' is the unknown value // returned from attribute resolution. partVars, _ := NewPartialActivation( - map[string]interface{}{"a": []int64{1, 2}}, + map[string]any{"a": []int64{1, 2}}, NewAttributePattern("b")) val, err := a.Resolve(partVars) if err != nil { @@ -261,7 +261,7 @@ func TestAttributePattern_CrossReference(t *testing.T) { // patterns specified. This changes the evaluation behavior slightly, but the end // result is the same. partVars, _ = NewPartialActivation( - map[string]interface{}{"a": []int64{1, 2}}, + map[string]any{"a": []int64{1, 2}}, NewAttributePattern("a").QualInt(0), NewAttributePattern("b")) val, err = a.Resolve(partVars) @@ -276,7 +276,7 @@ func TestAttributePattern_CrossReference(t *testing.T) { // have values. However, since the attribute being pattern matched is just 'a.b', // the outcome will indicate that 'a[b]' is unknown. partVars, _ = NewPartialActivation( - map[string]interface{}{"a": []int64{1, 2}, "b": 0}, + map[string]any{"a": []int64{1, 2}, "b": 0}, NewAttributePattern("a").QualInt(0).QualString("c")) val, err = a.Resolve(partVars) if err != nil { @@ -289,7 +289,7 @@ func TestAttributePattern_CrossReference(t *testing.T) { // Test a positive case that returns a valid value even though the attribugte factory // is the partial attribute factory. partVars, _ = NewPartialActivation( - map[string]interface{}{"a": []int64{1, 2}, "b": 0}) + map[string]any{"a": []int64{1, 2}, "b": 0}) val, err = a.Resolve(partVars) if err != nil { t.Fatal(err) @@ -300,7 +300,7 @@ func TestAttributePattern_CrossReference(t *testing.T) { // Ensure the unknown attribute id moves when the attribute becomes more specific. partVars, _ = NewPartialActivation( - map[string]interface{}{"a": []int64{1, 2}, "b": 0}, + map[string]any{"a": []int64{1, 2}, "b": 0}, NewAttributePattern("a").QualInt(0).QualString("c")) // Qualify a[b] with 'c', a[b].c c, _ := fac.NewQualifier(nil, 3, "c") diff --git a/interpreter/attributes.go b/interpreter/attributes.go index 4f1772ea..579a98ad 100644 --- a/interpreter/attributes.go +++ b/interpreter/attributes.go @@ -61,7 +61,7 @@ type AttributeFactory interface { // The qualifier may consider the object type being qualified, if present. If absent, the // qualification should be considered dynamic and the qualification should still work, though // it may be sub-optimal. - NewQualifier(objType *exprpb.Type, qualID int64, val interface{}) (Qualifier, error) + NewQualifier(objType *exprpb.Type, qualID int64, val any) (Qualifier, error) } // Qualifier marker interface for designating different qualifier values and where they appear @@ -72,7 +72,7 @@ type Qualifier interface { // Qualify performs a qualification, e.g. field selection, on the input object and returns // the value or error that results. - Qualify(vars Activation, obj interface{}) (interface{}, error) + Qualify(vars Activation, obj any) (any, error) } // ConstantQualifier interface embeds the Qualifier interface and provides an option to inspect the @@ -95,7 +95,7 @@ type Attribute interface { AddQualifier(Qualifier) (Attribute, error) // Resolve returns the value of the Attribute given the current Activation. - Resolve(Activation) (interface{}, error) + Resolve(Activation) (any, error) } // NamespacedAttribute values are a variable within a namespace, and an optional set of qualifiers @@ -114,7 +114,7 @@ type NamespacedAttribute interface { // If an error is encountered during attribute resolution, it will be returned immediately. // If the attribute cannot be resolved within the Activation, the result must be: `nil`, // `false`, `nil`. - TryResolve(Activation) (interface{}, bool, error) + TryResolve(Activation) (any, bool, error) } // NewAttributeFactory returns a default AttributeFactory which is produces Attribute values @@ -192,7 +192,7 @@ func (r *attrFactory) RelativeAttribute(id int64, operand Interpretable) Attribu // NewQualifier is an implementation of the AttributeFactory interface. func (r *attrFactory) NewQualifier(objType *exprpb.Type, qualID int64, - val interface{}) (Qualifier, error) { + val any) (Qualifier, error) { // Before creating a new qualifier check to see if this is a protobuf message field access. // If so, use the precomputed GetFrom qualification method rather than the standard // stringQualifier. @@ -256,7 +256,7 @@ func (a *absoluteAttribute) Qualifiers() []Qualifier { } // Qualify is an implementation of the Qualifier interface method. -func (a *absoluteAttribute) Qualify(vars Activation, obj interface{}) (interface{}, error) { +func (a *absoluteAttribute) Qualify(vars Activation, obj any) (any, error) { val, err := a.Resolve(vars) if err != nil { return nil, err @@ -274,7 +274,7 @@ func (a *absoluteAttribute) Qualify(vars Activation, obj interface{}) (interface // Resolve returns the resolved Attribute value given the Activation, or error if the Attribute // variable is not found, or if its Qualifiers cannot be applied successfully. -func (a *absoluteAttribute) Resolve(vars Activation) (interface{}, error) { +func (a *absoluteAttribute) Resolve(vars Activation) (any, error) { obj, found, err := a.TryResolve(vars) if err != nil { return nil, err @@ -295,7 +295,7 @@ func (a *absoluteAttribute) String() string { // // If the variable name cannot be found as an Activation variable or in the TypeProvider as // a type, then the result is `nil`, `false`, `nil` per the interface requirement. -func (a *absoluteAttribute) TryResolve(vars Activation) (interface{}, bool, error) { +func (a *absoluteAttribute) TryResolve(vars Activation) (any, bool, error) { for _, nm := range a.namespaceNames { // If the variable is found, process it. Otherwise, wait until the checks to // determine whether the type is unknown before returning. @@ -361,7 +361,7 @@ func (a *conditionalAttribute) AddQualifier(qual Qualifier) (Attribute, error) { } // Qualify is an implementation of the Qualifier interface method. -func (a *conditionalAttribute) Qualify(vars Activation, obj interface{}) (interface{}, error) { +func (a *conditionalAttribute) Qualify(vars Activation, obj any) (any, error) { val, err := a.Resolve(vars) if err != nil { return nil, err @@ -378,7 +378,7 @@ func (a *conditionalAttribute) Qualify(vars Activation, obj interface{}) (interf } // Resolve evaluates the condition, and then resolves the truthy or falsy branch accordingly. -func (a *conditionalAttribute) Resolve(vars Activation) (interface{}, error) { +func (a *conditionalAttribute) Resolve(vars Activation) (any, error) { val := a.expr.Eval(vars) if types.IsError(val) { return nil, val.(*types.Err) @@ -446,21 +446,21 @@ func findMax(x, y int64) int64 { // // 1. Create a maybe attribute from a simple identifier when it occurs in a parsed-only expression // -// mb = MaybeAttribute(, "a") +// mb = MaybeAttribute(, "a") // -// Initializing the maybe attribute creates an absolute attribute internally which includes the -// possible namespaced names of the attribute. In this example, let's assume we are in namespace -// 'ns', then the maybe is either one of the following variable names: +// Initializing the maybe attribute creates an absolute attribute internally which includes the +// possible namespaced names of the attribute. In this example, let's assume we are in namespace +// 'ns', then the maybe is either one of the following variable names: // -// possible variables names -- ns.a, a +// possible variables names -- ns.a, a // // 2. Adding a qualifier to the maybe means that the variable name could be a longer qualified -// name, or a field selection on one of the possible variable names produced earlier: +// name, or a field selection on one of the possible variable names produced earlier: // -// mb.AddQualifier("b") +// mb.AddQualifier("b") // -// possible variables names -- ns.a.b, a.b -// possible field selection -- ns.a['b'], a['b'] +// possible variables names -- ns.a.b, a.b +// possible field selection -- ns.a['b'], a['b'] // // If none of the attributes within the maybe resolves a value, the result is an error. func (a *maybeAttribute) AddQualifier(qual Qualifier) (Attribute, error) { @@ -491,7 +491,7 @@ func (a *maybeAttribute) AddQualifier(qual Qualifier) (Attribute, error) { } // Qualify is an implementation of the Qualifier interface method. -func (a *maybeAttribute) Qualify(vars Activation, obj interface{}) (interface{}, error) { +func (a *maybeAttribute) Qualify(vars Activation, obj any) (any, error) { val, err := a.Resolve(vars) if err != nil { return nil, err @@ -509,7 +509,7 @@ func (a *maybeAttribute) Qualify(vars Activation, obj interface{}) (interface{}, // Resolve follows the variable resolution rules to determine whether the attribute is a variable // or a field selection. -func (a *maybeAttribute) Resolve(vars Activation) (interface{}, error) { +func (a *maybeAttribute) Resolve(vars Activation) (any, error) { for _, attr := range a.attrs { obj, found, err := attr.TryResolve(vars) // Return an error if one is encountered. @@ -561,7 +561,7 @@ func (a *relativeAttribute) AddQualifier(qual Qualifier) (Attribute, error) { } // Qualify is an implementation of the Qualifier interface method. -func (a *relativeAttribute) Qualify(vars Activation, obj interface{}) (interface{}, error) { +func (a *relativeAttribute) Qualify(vars Activation, obj any) (any, error) { val, err := a.Resolve(vars) if err != nil { return nil, err @@ -578,7 +578,7 @@ func (a *relativeAttribute) Qualify(vars Activation, obj interface{}) (interface } // Resolve expression value and qualifier relative to the expression result. -func (a *relativeAttribute) Resolve(vars Activation) (interface{}, error) { +func (a *relativeAttribute) Resolve(vars Activation) (any, error) { // First, evaluate the operand. v := a.operand.Eval(vars) if types.IsError(v) { @@ -589,7 +589,7 @@ func (a *relativeAttribute) Resolve(vars Activation) (interface{}, error) { } // Next, qualify it. Qualification handles unknowns as well, so there's no need to recheck. var err error - var obj interface{} = v + var obj any = v for _, qual := range a.qualifiers { obj, err = qual.Qualify(vars, obj) if err != nil { @@ -604,7 +604,7 @@ func (a *relativeAttribute) String() string { return fmt.Sprintf("id: %v, operand: %v", a.id, a.operand) } -func newQualifier(adapter ref.TypeAdapter, id int64, v interface{}) (Qualifier, error) { +func newQualifier(adapter ref.TypeAdapter, id int64, v any) (Qualifier, error) { var qual Qualifier switch val := v.(type) { case Attribute: @@ -672,12 +672,12 @@ func (q *stringQualifier) ID() int64 { } // Qualify implements the Qualifier interface method. -func (q *stringQualifier) Qualify(vars Activation, obj interface{}) (interface{}, error) { +func (q *stringQualifier) Qualify(vars Activation, obj any) (any, error) { s := q.value isMap := false isKey := false switch o := obj.(type) { - case map[string]interface{}: + case map[string]any: isMap = true obj, isKey = o[s] case map[string]string: @@ -748,7 +748,7 @@ func (q *intQualifier) ID() int64 { } // Qualify implements the Qualifier interface method. -func (q *intQualifier) Qualify(vars Activation, obj interface{}) (interface{}, error) { +func (q *intQualifier) Qualify(vars Activation, obj any) (any, error) { i := q.value isMap := false isKey := false @@ -758,16 +758,16 @@ func (q *intQualifier) Qualify(vars Activation, obj interface{}) (interface{}, e // of specialized map types supported by string qualifiers since they are less frequently used // than string-based map keys. Additional specializations may be added in the future if // desired. - case map[int]interface{}: + case map[int]any: isMap = true obj, isKey = o[int(i)] - case map[int32]interface{}: + case map[int32]any: isMap = true obj, isKey = o[int32(i)] - case map[int64]interface{}: + case map[int64]any: isMap = true obj, isKey = o[i] - case []interface{}: + case []any: isIndex = i >= 0 && i < int64(len(o)) if isIndex { obj = o[i] @@ -863,7 +863,7 @@ func (q *uintQualifier) ID() int64 { } // Qualify implements the Qualifier interface method. -func (q *uintQualifier) Qualify(vars Activation, obj interface{}) (interface{}, error) { +func (q *uintQualifier) Qualify(vars Activation, obj any) (any, error) { u := q.value isMap := false isKey := false @@ -872,13 +872,13 @@ func (q *uintQualifier) Qualify(vars Activation, obj interface{}) (interface{}, // of specialized map types supported by string qualifiers since they are less frequently used // than string-based map keys. Additional specializations may be added in the future if // desired. - case map[uint]interface{}: + case map[uint]any: isMap = true obj, isKey = o[uint(u)] - case map[uint32]interface{}: + case map[uint32]any: isMap = true obj, isKey = o[uint32(u)] - case map[uint64]interface{}: + case map[uint64]any: isMap = true obj, isKey = o[u] case types.Unknown: @@ -919,7 +919,7 @@ func (q *boolQualifier) ID() int64 { } // Qualify implements the Qualifier interface method. -func (q *boolQualifier) Qualify(vars Activation, obj interface{}) (interface{}, error) { +func (q *boolQualifier) Qualify(vars Activation, obj any) (any, error) { b := q.value isKey := false switch o := obj.(type) { @@ -927,7 +927,7 @@ func (q *boolQualifier) Qualify(vars Activation, obj interface{}) (interface{}, // of specialized map types supported by string qualifiers since they are less frequently used // than string-based map keys. Additional specializations may be added in the future if // desired. - case map[bool]interface{}: + case map[bool]any: obj, isKey = o[b] case types.Unknown: return o, nil @@ -970,7 +970,7 @@ func (q *fieldQualifier) ID() int64 { } // Qualify implements the Qualifier interface method. -func (q *fieldQualifier) Qualify(vars Activation, obj interface{}) (interface{}, error) { +func (q *fieldQualifier) Qualify(vars Activation, obj any) (any, error) { if rv, ok := obj.(ref.Val); ok { obj = rv.Value() } @@ -1005,7 +1005,7 @@ func (q *doubleQualifier) ID() int64 { } // Qualify implements the Qualifier interface method. -func (q *doubleQualifier) Qualify(vars Activation, obj interface{}) (interface{}, error) { +func (q *doubleQualifier) Qualify(vars Activation, obj any) (any, error) { switch o := obj.(type) { case types.Unknown: return o, nil @@ -1020,7 +1020,7 @@ func (q *doubleQualifier) Qualify(vars Activation, obj interface{}) (interface{} // refResolve attempts to convert the value to a CEL value and then uses reflection methods // to try and resolve the qualifier. -func refResolve(adapter ref.TypeAdapter, idx ref.Val, obj interface{}) (ref.Val, error) { +func refResolve(adapter ref.TypeAdapter, idx ref.Val, obj any) (ref.Val, error) { celVal := adapter.NativeToValue(obj) mapper, isMapper := celVal.(traits.Mapper) if isMapper { diff --git a/interpreter/attributes_test.go b/interpreter/attributes_test.go index 9ee5007f..1ac76f41 100644 --- a/interpreter/attributes_test.go +++ b/interpreter/attributes_test.go @@ -39,9 +39,9 @@ func TestAttributesAbsoluteAttr(t *testing.T) { t.Fatal(err) } attrs := NewAttributeFactory(cont, reg, reg) - vars, _ := NewActivation(map[string]interface{}{ - "acme.a": map[string]interface{}{ - "b": map[uint]interface{}{ + vars, _ := NewActivation(map[string]any{ + "acme.a": map[string]any{ + "b": map[uint]any{ 4: map[bool]string{ false: "success", }, @@ -92,8 +92,8 @@ func TestAttributesAbsoluteAttr_Type(t *testing.T) { func TestAttributesRelativeAttr(t *testing.T) { reg := newTestRegistry(t) attrs := NewAttributeFactory(containers.DefaultContainer, reg, reg) - data := map[string]interface{}{ - "a": map[int]interface{}{ + data := map[string]any{ + "a": map[int]any{ -1: []int32{2, 42}, }, "b": 1, @@ -134,8 +134,8 @@ func TestAttributesRelativeAttr_OneOf(t *testing.T) { t.Fatal(err) } attrs := NewAttributeFactory(cont, reg, reg) - data := map[string]interface{}{ - "a": map[int]interface{}{ + data := map[string]any{ + "a": map[int]any{ -1: []int32{2, 42}, }, "acme.b": 1, @@ -179,12 +179,12 @@ func TestAttributesRelativeAttr_OneOf(t *testing.T) { func TestAttributesRelativeAttr_Conditional(t *testing.T) { reg := newTestRegistry(t) attrs := NewAttributeFactory(containers.DefaultContainer, reg, reg) - data := map[string]interface{}{ - "a": map[int]interface{}{ + data := map[string]any{ + "a": map[int]any{ -1: []int32{2, 42}, }, "b": []int{0, 1}, - "c": []interface{}{1, 0}, + "c": []any{1, 0}, } vars, _ := NewActivation(data) @@ -233,9 +233,9 @@ func TestAttributesRelativeAttr_Relative(t *testing.T) { } reg := newTestRegistry(t) attrs := NewAttributeFactory(cont, reg, reg) - data := map[string]interface{}{ - "a": map[int]interface{}{ - -1: map[string]interface{}{ + data := map[string]any{ + "a": map[int]any{ + -1: map[string]any{ "first": uint(1), "second": uint(2), "third": uint(3), @@ -272,7 +272,7 @@ func TestAttributesRelativeAttr_Relative(t *testing.T) { // This is equivalent to: // .a[-1]["second"] -> 2u obj := NewConstValue(1, reg.NativeToValue(data)) - mp := NewConstValue(1, reg.NativeToValue(map[uint32]interface{}{ + mp := NewConstValue(1, reg.NativeToValue(map[uint32]any{ 1: "first", 2: "second", 3: "third", @@ -307,8 +307,8 @@ func TestAttributesOneofAttr(t *testing.T) { t.Fatal(err) } attrs := NewAttributeFactory(cont, reg, reg) - data := map[string]interface{}{ - "a": map[string]interface{}{ + data := map[string]any{ + "a": map[string]any{ "b": []int32{2, 42}, }, "acme.a.b": 1, @@ -336,12 +336,12 @@ func TestAttributesOneofAttr(t *testing.T) { func TestAttributesConditionalAttr_TrueBranch(t *testing.T) { reg := newTestRegistry(t) attrs := NewAttributeFactory(containers.DefaultContainer, reg, reg) - data := map[string]interface{}{ - "a": map[int]interface{}{ + data := map[string]any{ + "a": map[int]any{ -1: []int32{2, 42}, }, - "b": map[string]interface{}{ - "c": map[int32]interface{}{ + "b": map[string]any{ + "c": map[int32]any{ -1: []uint{2, 42}, }, }, @@ -374,12 +374,12 @@ func TestAttributesConditionalAttr_TrueBranch(t *testing.T) { func TestAttributesConditionalAttr_FalseBranch(t *testing.T) { reg := newTestRegistry(t) attrs := NewAttributeFactory(containers.DefaultContainer, reg, reg) - data := map[string]interface{}{ - "a": map[int]interface{}{ + data := map[string]any{ + "a": map[int]any{ -1: []int32{2, 42}, }, - "b": map[string]interface{}{ - "c": map[int32]interface{}{ + "b": map[string]any{ + "c": map[int32]any{ -1: []uint{2, 42}, }, }, @@ -452,7 +452,7 @@ func BenchmarkResolverFieldQualifier(b *testing.B) { } reg := newBenchRegistry(b, msg) attrs := NewAttributeFactory(containers.DefaultContainer, reg, reg) - vars, _ := NewActivation(map[string]interface{}{ + vars, _ := NewActivation(map[string]any{ "msg": msg, }) attr := attrs.AbsoluteAttribute(1, "msg") @@ -483,7 +483,7 @@ func TestResolverCustomQualifier(t *testing.T) { msg := &proto3pb.TestAllTypes_NestedMessage{ Bb: 123, } - vars, _ := NewActivation(map[string]interface{}{ + vars, _ := NewActivation(map[string]any{ "msg": msg, }) attr := attrs.AbsoluteAttribute(1, "msg") @@ -509,9 +509,9 @@ func TestResolverCustomQualifier(t *testing.T) { func TestAttributesMissingMsg(t *testing.T) { reg := newTestRegistry(t) attrs := NewAttributeFactory(containers.DefaultContainer, reg, reg) - any, _ := anypb.New(&proto3pb.TestAllTypes{}) - vars, _ := NewActivation(map[string]interface{}{ - "missing_msg": any, + anyPB, _ := anypb.New(&proto3pb.TestAllTypes{}) + vars, _ := NewActivation(map[string]any{ + "missing_msg": anyPB, }) // missing_msg.field @@ -530,9 +530,9 @@ func TestAttributesMissingMsg(t *testing.T) { func TestAttributeMissingMsg_UnknownField(t *testing.T) { reg := newTestRegistry(t) attrs := NewPartialAttributeFactory(containers.DefaultContainer, reg, reg) - any, _ := anypb.New(&proto3pb.TestAllTypes{}) - vars, _ := NewPartialActivation(map[string]interface{}{ - "missing_msg": any, + anyPB, _ := anypb.New(&proto3pb.TestAllTypes{}) + vars, _ := NewPartialActivation(map[string]any{ + "missing_msg": anyPB, }, NewAttributePattern("missing_msg").QualString("field")) // missing_msg.field @@ -553,16 +553,16 @@ func TestAttributeStateTracking(t *testing.T) { var tests = []struct { expr string env []*exprpb.Decl - in map[string]interface{} + in map[string]any out ref.Val - state map[int64]interface{} + state map[int64]any }{ { expr: `[{"field": true}][0].field`, env: []*exprpb.Decl{}, - in: map[string]interface{}{}, + in: map[string]any{}, out: types.True, - state: map[int64]interface{}{ + state: map[int64]any{ // overall expression 1: true, // [{"field": true}][0] @@ -578,15 +578,15 @@ func TestAttributeStateTracking(t *testing.T) { decls.Int, decls.NewMapType(decls.String, decls.Bool))), }, - in: map[string]interface{}{ - "a": map[int64]interface{}{ + in: map[string]any{ + "a": map[int64]any{ 1: map[string]bool{ "two": true, }, }, }, out: types.True, - state: map[int64]interface{}{ + state: map[int64]any{ // overall expression 1: true, // a[1] @@ -602,20 +602,20 @@ func TestAttributeStateTracking(t *testing.T) { decls.Int, decls.NewMapType(decls.Dyn, decls.Dyn))), }, - in: map[string]interface{}{ - "a": map[int64]interface{}{ - 1: map[int64]interface{}{ + in: map[string]any{ + "a": map[int64]any{ + 1: map[int64]any{ 1: 0, 2: []string{"index", "middex", "outdex", "dex"}, }, }, }, out: types.String("dex"), - state: map[int64]interface{}{ + state: map[int64]any{ // overall expression 1: "dex", // a[1] - 2: map[int64]interface{}{ + 2: map[int64]any{ 1: 0, 2: []string{"index", "middex", "outdex", "dex"}, }, @@ -632,20 +632,20 @@ func TestAttributeStateTracking(t *testing.T) { decls.Int, decls.NewMapType(decls.Dyn, decls.Dyn))), }, - in: map[string]interface{}{ - "a": map[int64]interface{}{ - 1: map[int64]interface{}{ + in: map[string]any{ + "a": map[int64]any{ + 1: map[int64]any{ 1: 0, 2: []string{"index", "middex", "outdex", "dex"}, }, }, }, out: types.String("index"), - state: map[int64]interface{}{ + state: map[int64]any{ // overall expression 1: "index", // a[1] - 2: map[int64]interface{}{ + 2: map[int64]any{ 1: 0, 2: []string{"index", "middex", "outdex", "dex"}, }, @@ -655,7 +655,7 @@ func TestAttributeStateTracking(t *testing.T) { 6: "index", // dynamic index into a[1][2] // a[1] - 8: map[int64]interface{}{ + 8: map[int64]any{ 1: 0, 2: []string{"index", "middex", "outdex", "dex"}, }, @@ -724,7 +724,7 @@ func BenchmarkResolverCustomQualifier(b *testing.B) { msg := &proto3pb.TestAllTypes_NestedMessage{ Bb: 123, } - vars, _ := NewActivation(map[string]interface{}{ + vars, _ := NewActivation(map[string]any{ "msg": msg, }) attr := attrs.AbsoluteAttribute(1, "msg") @@ -744,7 +744,7 @@ type custAttrFactory struct { } func (r *custAttrFactory) NewQualifier(objType *exprpb.Type, - qualID int64, val interface{}) (Qualifier, error) { + qualID int64, val any) (Qualifier, error) { if objType.GetMessageType() == "google.expr.proto3.test.TestAllTypes.NestedMessage" { return &nestedMsgQualifier{id: qualID, field: val.(string)}, nil } @@ -760,7 +760,7 @@ func (q *nestedMsgQualifier) ID() int64 { return q.id } -func (q *nestedMsgQualifier) Qualify(vars Activation, obj interface{}) (interface{}, error) { +func (q *nestedMsgQualifier) Qualify(vars Activation, obj any) (any, error) { pb := obj.(*proto3pb.TestAllTypes_NestedMessage) return pb.GetBb(), nil } @@ -770,7 +770,7 @@ func (q *nestedMsgQualifier) Cost() (min, max int64) { return 0, 0 } -func makeQualifier(b *testing.B, attrs AttributeFactory, typ *exprpb.Type, qualID int64, val interface{}) Qualifier { +func makeQualifier(b *testing.B, attrs AttributeFactory, typ *exprpb.Type, qualID int64, val any) Qualifier { b.Helper() qual, err := attrs.NewQualifier(typ, qualID, val) if err != nil { diff --git a/interpreter/coster.go b/interpreter/coster.go index ac573d57..c79862c4 100644 --- a/interpreter/coster.go +++ b/interpreter/coster.go @@ -26,7 +26,7 @@ type Coster interface { } // estimateCost returns the heuristic cost interval for the program. -func estimateCost(i interface{}) (min, max int64) { +func estimateCost(i any) (min, max int64) { c, ok := i.(Coster) if !ok { return 0, math.MaxInt64 diff --git a/interpreter/functions/functions.go b/interpreter/functions/functions.go index dd1e9ddd..e1eb73dc 100644 --- a/interpreter/functions/functions.go +++ b/interpreter/functions/functions.go @@ -58,5 +58,5 @@ type UnaryOp func(value ref.Val) ref.Val type BinaryOp func(lhs ref.Val, rhs ref.Val) ref.Val // FunctionOp is a function with accepts zero or more arguments and produces -// an value (as interface{}) or error as a result. +// an value or error as a result. type FunctionOp func(values ...ref.Val) ref.Val diff --git a/interpreter/interpretable.go b/interpreter/interpretable.go index 4fdd1202..dfd2e270 100644 --- a/interpreter/interpretable.go +++ b/interpreter/interpretable.go @@ -64,10 +64,10 @@ type InterpretableAttribute interface { // Qualify replicates the Attribute.Qualify method to permit extension and interception // of object qualification. - Qualify(vars Activation, obj interface{}) (interface{}, error) + Qualify(vars Activation, obj any) (any, error) // Resolve returns the value of the Attribute given the current Activation. - Resolve(Activation) (interface{}, error) + Resolve(Activation) (any, error) } // InterpretableCall interface for inspecting Interpretable instructions related to function calls. @@ -979,7 +979,7 @@ func (e *evalWatchConstQual) Cost() (min, max int64) { } // Qualify observes the qualification of a object via a constant boolean, int, string, or uint. -func (e *evalWatchConstQual) Qualify(vars Activation, obj interface{}) (interface{}, error) { +func (e *evalWatchConstQual) Qualify(vars Activation, obj any) (any, error) { out, err := e.ConstantQualifier.Qualify(vars, obj) var val ref.Val if err != nil { @@ -992,7 +992,7 @@ func (e *evalWatchConstQual) Qualify(vars Activation, obj interface{}) (interfac } // QualifierValueEquals tests whether the incoming value is equal to the qualifying constant. -func (e *evalWatchConstQual) QualifierValueEquals(value interface{}) bool { +func (e *evalWatchConstQual) QualifierValueEquals(value any) bool { qve, ok := e.ConstantQualifier.(qualifierValueEquator) return ok && qve.QualifierValueEquals(value) } @@ -1010,7 +1010,7 @@ func (e *evalWatchQual) Cost() (min, max int64) { } // Qualify observes the qualification of a object via a value computed at runtime. -func (e *evalWatchQual) Qualify(vars Activation, obj interface{}) (interface{}, error) { +func (e *evalWatchQual) Qualify(vars Activation, obj any) (any, error) { out, err := e.Qualifier.Qualify(vars, obj) var val ref.Val if err != nil { @@ -1220,11 +1220,11 @@ func (a *evalAttr) Eval(ctx Activation) ref.Val { } // Qualify proxies to the Attribute's Qualify method. -func (a *evalAttr) Qualify(ctx Activation, obj interface{}) (interface{}, error) { +func (a *evalAttr) Qualify(ctx Activation, obj any) (any, error) { return a.attr.Qualify(ctx, obj) } // Resolve proxies to the Attribute's Resolve method. -func (a *evalAttr) Resolve(ctx Activation) (interface{}, error) { +func (a *evalAttr) Resolve(ctx Activation) (any, error) { return a.attr.Resolve(ctx) } diff --git a/interpreter/interpreter.go b/interpreter/interpreter.go index b3fd14f8..707a6105 100644 --- a/interpreter/interpreter.go +++ b/interpreter/interpreter.go @@ -29,19 +29,17 @@ import ( type Interpreter interface { // NewInterpretable creates an Interpretable from a checked expression and an // optional list of InterpretableDecorator values. - NewInterpretable(checked *exprpb.CheckedExpr, - decorators ...InterpretableDecorator) (Interpretable, error) + NewInterpretable(checked *exprpb.CheckedExpr, decorators ...InterpretableDecorator) (Interpretable, error) // NewUncheckedInterpretable returns an Interpretable from a parsed expression // and an optional list of InterpretableDecorator values. - NewUncheckedInterpretable(expr *exprpb.Expr, - decorators ...InterpretableDecorator) (Interpretable, error) + NewUncheckedInterpretable(expr *exprpb.Expr, decorators ...InterpretableDecorator) (Interpretable, error) } // EvalObserver is a functional interface that accepts an expression id and an observed value. // The id identifies the expression that was evaluated, the programStep is the Interpretable or Qualifier that // was evaluated and value is the result of the evaluation. -type EvalObserver func(id int64, programStep interface{}, value ref.Val) +type EvalObserver func(id int64, programStep any, value ref.Val) // Observe constructs a decorator that calls all the provided observers in order after evaluating each Interpretable // or Qualifier during program evaluation. @@ -49,7 +47,7 @@ func Observe(observers ...EvalObserver) InterpretableDecorator { if len(observers) == 1 { return decObserveEval(observers[0]) } - observeFn := func(id int64, programStep interface{}, val ref.Val) { + observeFn := func(id int64, programStep any, val ref.Val) { for _, observer := range observers { observer(id, programStep, val) } @@ -96,7 +94,7 @@ func TrackState(state EvalState) InterpretableDecorator { // This decorator is not thread-safe, and the EvalState must be reset between Eval() // calls. func EvalStateObserver(state EvalState) EvalObserver { - return func(id int64, programStep interface{}, val ref.Val) { + return func(id int64, programStep any, val ref.Val) { state.SetValue(id, val) } } diff --git a/interpreter/interpreter_test.go b/interpreter/interpreter_test.go index a2cda184..f562b2db 100644 --- a/interpreter/interpreter_test.go +++ b/interpreter/interpreter_test.go @@ -61,8 +61,8 @@ type testCase struct { unchecked bool extraOpts []InterpretableDecorator - in map[string]interface{} - out interface{} + in map[string]any + out any err string progErr string } @@ -181,7 +181,7 @@ var ( }, }, }, - in: map[string]interface{}{ + in: map[string]any{ "a": 1, "b": 2, "c": 3, "d": 4, }, }, @@ -273,8 +273,8 @@ var ( env: []*exprpb.Decl{ decls.NewVar("headers", decls.NewMapType(decls.String, decls.String)), }, - in: map[string]interface{}{ - "headers": map[string]interface{}{ + in: map[string]any{ + "headers": map[string]any{ "ip": "10.0.1.2", "path": "/admin/edit", "token": "admin", @@ -297,7 +297,7 @@ var ( decls.NewVar("headers.path", decls.String), decls.NewVar("headers.token", decls.String), }, - in: map[string]interface{}{ + in: map[string]any{ "headers.ip": "10.0.1.2", "headers.path": "/admin/edit", "headers.token": "admin", @@ -312,7 +312,7 @@ var ( decls.NewVar("b", decls.Double), decls.NewVar("c", decls.NewListType(decls.String)), }, - in: map[string]interface{}{ + in: map[string]any{ "a": true, "b": 2.0, "c": []string{"hello"}, @@ -326,7 +326,7 @@ var ( decls.NewVar("m", decls.NewListType(decls.Int)), decls.NewVar("x", decls.Bool), }, - in: map[string]interface{}{ + in: map[string]any{ "m": []int{-1}, "x": false, }, @@ -341,7 +341,7 @@ var ( decls.NewVar("b", decls.Dyn), decls.NewVar("x", decls.Bool), }, - in: map[string]interface{}{ + in: map[string]any{ "m": []int{1}, "x": false, "a": time.Millisecond, @@ -358,7 +358,7 @@ var ( decls.NewVar("b", decls.Dyn), decls.NewVar("x", decls.Bool), }, - in: map[string]interface{}{ + in: map[string]any{ "m": []int{1}, "x": false, "a": int32(1), @@ -418,7 +418,7 @@ var ( env: []*exprpb.Decl{ decls.NewVar("x", decls.Dyn), }, - in: map[string]interface{}{"x": 6}, + in: map[string]any{"x": 6}, }, { name: "in_var_list_uint", @@ -426,7 +426,7 @@ var ( env: []*exprpb.Decl{ decls.NewVar("x", decls.Dyn), }, - in: map[string]interface{}{"x": uint64(6)}, + in: map[string]any{"x": uint64(6)}, }, { name: "in_var_list_double", @@ -434,7 +434,7 @@ var ( env: []*exprpb.Decl{ decls.NewVar("x", decls.Dyn), }, - in: map[string]interface{}{"x": 6.0}, + in: map[string]any{"x": 6.0}, }, { name: "in_var_list_double_double", @@ -442,7 +442,7 @@ var ( env: []*exprpb.Decl{ decls.NewVar("x", decls.Int), }, - in: map[string]interface{}{"x": 6}, + in: map[string]any{"x": 6}, }, { name: "in_constant_map", @@ -487,7 +487,7 @@ var ( decls.NewVar("x", decls.String), decls.NewVar("y", decls.Int), }, - in: map[string]interface{}{ + in: map[string]any{ "x": "other-key", "y": 2, }, @@ -500,7 +500,7 @@ var ( decls.NewVar("x", decls.String), decls.NewVar("y", decls.Int), }, - in: map[string]interface{}{ + in: map[string]any{ "x": "other-value", "y": 2, }, @@ -514,8 +514,8 @@ var ( env: []*exprpb.Decl{ decls.NewVar("m", decls.NewMapType(decls.String, decls.Dyn)), }, - in: map[string]interface{}{ - "m": map[string]interface{}{ + in: map[string]any{ + "m": map[string]any{ "key": []uint{21, 42}, "null": nil, "0": 10, @@ -532,7 +532,7 @@ var ( decls.NewVar("x", decls.Dyn), decls.NewVar("y", decls.Dyn), }, - in: map[string]interface{}{ + in: map[string]any{ "x": float32(1.0), "y": uint(2), }, @@ -544,7 +544,7 @@ var ( decls.NewVar("x", decls.Dyn), decls.NewVar("y", decls.Dyn), }, - in: map[string]interface{}{ + in: map[string]any{ "x": float32(2.0), "y": uint(3), }, @@ -556,7 +556,7 @@ var ( env: []*exprpb.Decl{ decls.NewVar("x", decls.Dyn), }, - in: map[string]interface{}{ + in: map[string]any{ "x": 1.0, }, }, @@ -574,7 +574,7 @@ var ( env: []*exprpb.Decl{ decls.NewVar("x", decls.Dyn), }, - in: map[string]interface{}{ + in: map[string]any{ "x": time.Millisecond, }, err: "invalid qualifier type", @@ -621,7 +621,7 @@ var ( name: "literal_map", expr: `{'hi': 21, 'world': 42u}`, cost: []int64{0, 0}, - out: map[string]interface{}{ + out: map[string]any{ "hi": 21, "world": uint(42), }, @@ -754,7 +754,7 @@ var ( decls.NewVar("code", decls.String), decls.NewVar("tags", decls.NewListType(decls.String)), }, - in: map[string]interface{}{ + in: map[string]any{ "code": "222", "tags": []string{"a", "b"}, }, @@ -775,8 +775,8 @@ var ( env: []*exprpb.Decl{ decls.NewVar("elems", decls.NewListType(decls.Dyn)), }, - in: map[string]interface{}{ - "elems": []interface{}{0, 1, 2, 3, 4, uint(5), 6}, + in: map[string]any{ + "elems": []any{0, 1, 2, 3, 4, uint(5), 6}, }, }, { @@ -801,7 +801,7 @@ var ( env: []*exprpb.Decl{ decls.NewVar("pb2", decls.NewObjectType("google.expr.proto2.test.TestAllTypes")), }, - in: map[string]interface{}{ + in: map[string]any{ "pb2": &proto2pb.TestAllTypes{ RepeatedBool: []bool{false}, MapInt64NestedType: map[int64]*proto2pb.NestedTestAllTypes{ @@ -830,7 +830,7 @@ var ( decls.NewVar("pb3", decls.NewObjectType("google.expr.proto3.test.TestAllTypes")), }, container: "google.expr.proto3.test", - in: map[string]interface{}{ + in: map[string]any{ "pb3": &proto3pb.TestAllTypes{ RepeatedBool: []bool{false}, MapInt64NestedType: map[int64]*proto3pb.NestedTestAllTypes{ @@ -866,7 +866,7 @@ var ( env: []*exprpb.Decl{ decls.NewVar("input", decls.String), }, - in: map[string]interface{}{ + in: map[string]any{ "input": "kathmandu", }, }, @@ -881,7 +881,7 @@ var ( env: []*exprpb.Decl{ decls.NewVar("input", decls.String), }, - in: map[string]interface{}{ + in: map[string]any{ "input": "kathmandu", }, }, @@ -891,7 +891,7 @@ var ( env: []*exprpb.Decl{ decls.NewVar("input", decls.String), }, - in: map[string]interface{}{ + in: map[string]any{ "input": "kathmandu", }, extraOpts: []InterpretableDecorator{CompileRegexConstants(MatchesRegexOptimization)}, @@ -909,7 +909,7 @@ var ( decls.NewVar("pb3", decls.NewObjectType("google.expr.proto3.test.TestAllTypes")), }, - in: map[string]interface{}{ + in: map[string]any{ "pb3": &proto3pb.TestAllTypes{ NestedType: &proto3pb.TestAllTypes_SingleNestedMessage{ SingleNestedMessage: &proto3pb.TestAllTypes_NestedMessage{ @@ -929,7 +929,7 @@ var ( decls.NewVar("pb3", decls.NewObjectType("google.expr.proto3.test.TestAllTypes")), }, - in: map[string]interface{}{ + in: map[string]any{ "pb3": &proto3pb.TestAllTypes{ MapInt64NestedType: map[int64]*proto3pb.NestedTestAllTypes{ 0: { @@ -952,7 +952,7 @@ var ( decls.NewVar("ai", decls.Int), decls.NewVar("ar", decls.NewMapType(decls.String, decls.String)), }, - in: map[string]interface{}{ + in: map[string]any{ "ai": 20, "ar": map[string]string{ "foo": "bar", @@ -968,7 +968,7 @@ var ( decls.NewVar("ai", decls.Int), decls.NewVar("ar", decls.NewMapType(decls.String, decls.String)), }, - in: map[string]interface{}{ + in: map[string]any{ "ai": 2, "ar": map[string]string{ "foo": "bar", @@ -984,7 +984,7 @@ var ( decls.NewVar("ai", decls.Int), decls.NewVar("ar", decls.NewMapType(decls.String, decls.String)), }, - in: map[string]interface{}{ + in: map[string]any{ "ai": 2, "ar": map[string]string{ "foo": "baz", @@ -1028,7 +1028,7 @@ var ( env: []*exprpb.Decl{ decls.NewVar("a.b.c.d", decls.Int), }, - in: map[string]interface{}{ + in: map[string]any{ "a.b.c.d": 9, }, }, @@ -1038,7 +1038,7 @@ var ( cost: []int64{2, 2}, unchecked: true, container: "a.b", - in: map[string]interface{}{ + in: map[string]any{ "a.c.d": 9, }, }, @@ -1048,7 +1048,7 @@ var ( cost: []int64{2, 2}, unchecked: true, container: "a.b", - in: map[string]interface{}{ + in: map[string]any{ "a.b.c": map[string]int{ "d": 10, }, @@ -1072,8 +1072,8 @@ var ( env: []*exprpb.Decl{ decls.NewVar("m", decls.NewMapType(decls.String, decls.Dyn)), }, - in: map[string]interface{}{ - "m": map[string]interface{}{ + in: map[string]any{ + "m": map[string]any{ "strMap": map[string]string{"val": "string"}, "floatMap": map[string]float32{"val": 1.5}, "doubleMap": map[string]float64{"val": -2.0}, @@ -1105,8 +1105,8 @@ var ( env: []*exprpb.Decl{ decls.NewVar("m", decls.NewMapType(decls.String, decls.Dyn)), }, - in: map[string]interface{}{ - "m": map[string]interface{}{ + in: map[string]any{ + "m": map[string]any{ "boolStr": map[bool]string{true: "string"}, "boolFloat32": map[bool]float32{true: 1.5}, "boolFloat64": map[bool]float64{false: -2.1}, @@ -1117,7 +1117,7 @@ var ( "boolUint32": map[bool]uint32{true: 6}, "boolUint64": map[bool]uint64{false: 7}, "boolBool": map[bool]bool{true: true}, - "boolIface": map[bool]interface{}{false: true}, + "boolIface": map[bool]any{false: true}, }, }, }, @@ -1132,11 +1132,11 @@ var ( env: []*exprpb.Decl{ decls.NewVar("m", decls.NewMapType(decls.String, decls.Dyn)), }, - in: map[string]interface{}{ - "m": map[string]interface{}{ - "uintIface": map[uint]interface{}{1: "string"}, - "uint32Iface": map[uint32]interface{}{2: 1.5}, - "uint64Iface": map[uint64]interface{}{3: -2.1}, + in: map[string]any{ + "m": map[string]any{ + "uintIface": map[uint]any{1: "string"}, + "uint32Iface": map[uint32]any{2: 1.5}, + "uint64Iface": map[uint64]any{3: -2.1}, "uint64String": map[uint64]string{4: "three"}, }, }, @@ -1160,8 +1160,8 @@ var ( env: []*exprpb.Decl{ decls.NewVar("m", decls.NewMapType(decls.String, decls.Dyn)), }, - in: map[string]interface{}{ - "m": map[string]interface{}{ + in: map[string]any{ + "m": map[string]any{ "strList": []string{"string"}, "floatList": []float32{1.5}, "doubleList": []float64{-2.0}, @@ -1172,7 +1172,7 @@ var ( "uint32List": []uint32{7}, "uint64List": []uint64{8}, "boolList": []bool{true, false}, - "ifaceList": []interface{}{map[string]string{}}, + "ifaceList": []any{map[string]string{}}, }, }, }, @@ -1190,7 +1190,7 @@ var ( decls.NewVar("pb3", decls.NewObjectType("google.expr.proto3.test.TestAllTypes")), decls.NewVar("json", decls.NewMapType(decls.String, decls.Dyn)), }, - in: map[string]interface{}{ + in: map[string]any{ "a.b": map[string]bool{ "c": true, }, @@ -1229,7 +1229,7 @@ var ( cost: []int64{3, 26}, exhaustiveCost: []int64{26, 26}, types: []proto.Message{&proto2pb.TestAllTypes{}}, - in: map[string]interface{}{ + in: map[string]any{ "a": &proto2pb.TestAllTypes{}, }, env: []*exprpb.Decl{ @@ -1250,7 +1250,7 @@ var ( env: []*exprpb.Decl{ decls.NewVar("a", decls.NewObjectType("google.expr.proto3.test.TestAllTypes")), }, - in: map[string]interface{}{ + in: map[string]any{ "a": &proto3pb.TestAllTypes{ SingleInt64Wrapper: &wrapperspb.Int64Value{}, SingleStringWrapper: wrapperspb.String("hello"), @@ -1266,7 +1266,7 @@ var ( env: []*exprpb.Decl{ decls.NewVar("a", decls.NewObjectType("google.expr.proto3.test.TestAllTypes")), }, - in: map[string]interface{}{ + in: map[string]any{ "a": &proto3pb.TestAllTypes{ SingleUint64: 10, }, @@ -1290,7 +1290,7 @@ var ( types.NewEmptyRegistry(), ), }, - in: map[string]interface{}{ + in: map[string]any{ "a": &proto3pb.TestAllTypes_NestedMessage{ Bb: 101, }, @@ -1314,7 +1314,7 @@ var ( if !ok { return types.MaybeNoSuchOverloadErr(val) } - m := make(map[string]interface{}) + m := make(map[string]any) err := json.Unmarshal([]byte(str), &m) if err != nil { return types.NewErr("invalid json: %v", err) @@ -1332,7 +1332,7 @@ var ( decls.NewVar("a.b.c", decls.Int), decls.NewVar("a.b", decls.NewMapType(decls.String, decls.String)), }, - in: map[string]interface{}{ + in: map[string]any{ "a.b.c": 10, "a.b": map[string]string{ "c": "ten", @@ -1552,7 +1552,7 @@ func TestInterpreter_ProtoAttributeOpt(t *testing.T) { decls.NewVar("pb3", decls.NewObjectType("google.expr.proto3.test.TestAllTypes")), }, - in: map[string]interface{}{ + in: map[string]any{ "pb3": &proto3pb.TestAllTypes{ MapInt64NestedType: map[int64]*proto3pb.NestedTestAllTypes{ 0: { @@ -1622,7 +1622,7 @@ func TestInterpreter_ExhaustiveConditionalExpr(t *testing.T) { interpretable, _ := intr.NewUncheckedInterpretable( parsed.GetExpr(), ExhaustiveEval(), Observe(EvalStateObserver(state))) - vars, _ := NewActivation(map[string]interface{}{ + vars, _ := NewActivation(map[string]any{ "a": types.True, "b": types.Double(0.999), "c": types.NewStringList(reg, []string{"hello"})}) @@ -1649,7 +1649,7 @@ func TestInterpreter_InterruptableEval(t *testing.T) { env: []*exprpb.Decl{ decls.NewVar("items", decls.NewListType(decls.Int)), }, - in: map[string]interface{}{ + in: map[string]any{ "items": items, }, out: true, @@ -1686,7 +1686,7 @@ type contextActivation struct { interrupt func() bool } -func (ca *contextActivation) ResolveName(name string) (interface{}, bool) { +func (ca *contextActivation) ResolveName(name string) (any, bool) { if name == "#interrupted" { ca.interruptCount++ return ca.interruptCount%100 == 0 && ca.interrupt(), true @@ -1711,7 +1711,7 @@ func TestInterpreter_ExhaustiveLogicalOrEquals(t *testing.T) { i, _ := interp.NewUncheckedInterpretable( parsed.GetExpr(), ExhaustiveEval(), Observe(EvalStateObserver(state))) - vars, _ := NewActivation(map[string]interface{}{ + vars, _ := NewActivation(map[string]any{ "a": true, "b": "b", }) @@ -1774,7 +1774,7 @@ func TestInterpreter_SetProto2PrimitiveFields(t *testing.T) { SingleString: &str, SingleBool: &truth, } - vars, _ := NewActivation(map[string]interface{}{ + vars, _ := NewActivation(map[string]any{ "input": reg.NativeToValue(input), }) result := eval.Eval(vars) @@ -1810,8 +1810,8 @@ func TestInterpreter_MissingIdentInSelect(t *testing.T) { interp := NewStandardInterpreter(cont, reg, reg, attrs) i, _ := interp.NewInterpretable(checked) vars, _ := NewPartialActivation( - map[string]interface{}{ - "a.b": map[string]interface{}{ + map[string]any{ + "a.b": map[string]any{ "d": "hello", }, }, @@ -1904,7 +1904,7 @@ func testContainer(name string) *containers.Container { return cont } -func program(ctx interface{}, tst *testCase, opts ...InterpretableDecorator) (Interpretable, Activation, error) { +func program(ctx any, tst *testCase, opts ...InterpretableDecorator) (Interpretable, Activation, error) { // Configure the package. cont := containers.DefaultContainer if tst.container != "" { diff --git a/interpreter/planner.go b/interpreter/planner.go index 7f8a5beb..e86ec319 100644 --- a/interpreter/planner.go +++ b/interpreter/planner.go @@ -189,16 +189,7 @@ func (p *planner) planSelect(expr *exprpb.Expr) (Interpretable, error) { if err != nil { return nil, err } - - // Determine the field type if this is a proto message type. - var fieldType *ref.FieldType opType := p.typeMap[sel.GetOperand().GetId()] - if opType.GetMessageType() != "" { - ft, found := p.provider.FindFieldType(opType.GetMessageType(), sel.GetField()) - if found && ft.IsSet != nil && ft.GetFrom != nil { - fieldType = ft - } - } // If the Select was marked TestOnly, this is a presence test. // @@ -212,6 +203,14 @@ func (p *planner) planSelect(expr *exprpb.Expr) (Interpretable, error) { // it is not clear whether has should error or follow the convention defined for structured // values. if sel.TestOnly { + // Determine the field type if this is a proto message type. + var fieldType *ref.FieldType + if opType.GetMessageType() != "" { + ft, found := p.provider.FindFieldType(opType.GetMessageType(), sel.GetField()) + if found && ft.IsSet != nil && ft.GetFrom != nil { + fieldType = ft + } + } // Return the test only eval expression. return &evalTestOnly{ id: expr.GetId(), @@ -221,8 +220,7 @@ func (p *planner) planSelect(expr *exprpb.Expr) (Interpretable, error) { }, nil } // Build a qualifier. - qual, err := p.attrFactory.NewQualifier( - opType, expr.GetId(), sel.GetField()) + qual, err := p.attrFactory.NewQualifier(opType, expr.GetId(), sel.GetField()) if err != nil { return nil, err } @@ -497,8 +495,7 @@ func (p *planner) planCallIndex(expr *exprpb.Expr, args []Interpretable) (Interp opType := p.typeMap[expr.GetCallExpr().GetTarget().GetId()] indConst, isIndConst := ind.(InterpretableConst) if isIndConst { - qual, err := p.attrFactory.NewQualifier( - opType, expr.GetId(), indConst.Value()) + qual, err := p.attrFactory.NewQualifier(opType, expr.GetId(), indConst.Value()) if err != nil { return nil, err } @@ -507,8 +504,7 @@ func (p *planner) planCallIndex(expr *exprpb.Expr, args []Interpretable) (Interp } indAttr, isIndAttr := ind.(InterpretableAttribute) if isIndAttr { - qual, err := p.attrFactory.NewQualifier( - opType, expr.GetId(), indAttr) + qual, err := p.attrFactory.NewQualifier(opType, expr.GetId(), indAttr) if err != nil { return nil, err } diff --git a/interpreter/prune_test.go b/interpreter/prune_test.go index 507bdc7f..f20106a4 100644 --- a/interpreter/prune_test.go +++ b/interpreter/prune_test.go @@ -24,14 +24,14 @@ import ( ) type testInfo struct { - in interface{} + in any expr string out string } var testCases = []testInfo{ { - in: map[string]interface{}{ + in: map[string]any{ "msg": map[string]string{"foo": "bar"}, }, expr: `msg`, @@ -161,11 +161,11 @@ func unknownActivation(vars ...string) PartialActivation { for i, v := range vars { pats[i] = NewAttributePattern(v) } - a, _ := NewPartialActivation(map[string]interface{}{}, pats...) + a, _ := NewPartialActivation(map[string]any{}, pats...) return a } -func testActivation(t *testing.T, in interface{}) Activation { +func testActivation(t *testing.T, in any) Activation { t.Helper() if in == nil { return EmptyActivation() diff --git a/interpreter/runtimecost.go b/interpreter/runtimecost.go index 06b6b27e..42e64a44 100644 --- a/interpreter/runtimecost.go +++ b/interpreter/runtimecost.go @@ -36,7 +36,7 @@ type ActualCostEstimator interface { // CostObserver provides an observer that tracks runtime cost. func CostObserver(tracker *CostTracker) EvalObserver { - observer := func(id int64, programStep interface{}, val ref.Val) { + observer := func(id int64, programStep any, val ref.Val) { switch t := programStep.(type) { case ConstantQualifier: // TODO: Push identifiers on to the stack before observing constant qualifiers that apply to them diff --git a/interpreter/runtimecost_test.go b/interpreter/runtimecost_test.go index 10cce7ab..0bcd39e3 100644 --- a/interpreter/runtimecost_test.go +++ b/interpreter/runtimecost_test.go @@ -36,7 +36,7 @@ import ( func TestTrackCostAdvanced(t *testing.T) { var equalCases = []struct { - in interface{} + in any lhsExpr string rhsExpr string }{ @@ -72,7 +72,7 @@ func TestTrackCostAdvanced(t *testing.T) { } var smallerCases = []struct { - in interface{} + in any lhsExpr string rhsExpr string }{ @@ -160,7 +160,7 @@ func computeCost(t *testing.T, expr string, decls []*exprpb.Decl, ctx Activation return costTracker.cost, est, err } -func constructActivation(t *testing.T, in interface{}) Activation { +func constructActivation(t *testing.T, in any) Activation { t.Helper() if in == nil { return EmptyActivation() @@ -241,7 +241,7 @@ func TestRuntimeCost(t *testing.T) { expr string decls []*exprpb.Decl want uint64 - in interface{} + in any testFuncCost bool limit uint64 @@ -257,28 +257,28 @@ func TestRuntimeCost(t *testing.T) { expr: `input`, decls: []*exprpb.Decl{decls.NewVar("input", intList)}, want: 1, - in: map[string]interface{}{"input": []int{1, 2}}, + in: map[string]any{"input": []int{1, 2}}, }, { name: "select: map", expr: `input['key']`, decls: []*exprpb.Decl{decls.NewVar("input", decls.NewMapType(decls.String, decls.String))}, want: 2, - in: map[string]interface{}{"input": map[string]string{"key": "v"}}, + in: map[string]any{"input": map[string]string{"key": "v"}}, }, { name: "select: array index", expr: `input[0]`, decls: []*exprpb.Decl{decls.NewVar("input", decls.NewListType(decls.String))}, want: 2, - in: map[string]interface{}{"input": []string{"v"}}, + in: map[string]any{"input": []string{"v"}}, }, { name: "select: field", expr: `input.single_int32`, decls: []*exprpb.Decl{decls.NewVar("input", allTypes)}, want: 2, - in: map[string]interface{}{ + in: map[string]any{ "input": &proto3pb.TestAllTypes{ RepeatedBool: []bool{false}, MapInt64NestedType: map[int64]*proto3pb.NestedTestAllTypes{ @@ -293,21 +293,21 @@ func TestRuntimeCost(t *testing.T) { expr: `input['ke' + 'y']`, decls: []*exprpb.Decl{decls.NewVar("input", decls.NewMapType(decls.String, decls.String))}, want: 3, - in: map[string]interface{}{"input": map[string]string{"key": "v"}}, + in: map[string]any{"input": map[string]string{"key": "v"}}, }, { name: "expr select: array index", expr: `input[3-3]`, decls: []*exprpb.Decl{decls.NewVar("input", decls.NewListType(decls.String))}, want: 3, - in: map[string]interface{}{"input": []string{"v"}}, + in: map[string]any{"input": []string{"v"}}, }, { name: "select: field test only", expr: `has(input.single_int32)`, decls: []*exprpb.Decl{decls.NewVar("input", decls.NewObjectType("google.expr.proto3.test.TestAllTypes"))}, want: 0, - in: map[string]interface{}{ + in: map[string]any{ "input": &proto3pb.TestAllTypes{ RepeatedBool: []bool{false}, MapInt64NestedType: map[int64]*proto3pb.NestedTestAllTypes{ @@ -322,7 +322,7 @@ func TestRuntimeCost(t *testing.T) { expr: `input.getFullYear()`, decls: []*exprpb.Decl{decls.NewVar("input", decls.Timestamp)}, want: 8, - in: map[string]interface{}{"input": time.Now()}, + in: map[string]any{"input": time.Now()}, testFuncCost: true, }, { @@ -345,7 +345,7 @@ func TestRuntimeCost(t *testing.T) { decls: []*exprpb.Decl{decls.NewVar("input", allList)}, expr: `input.all(x, true)`, want: 2, - in: map[string]interface{}{ + in: map[string]any{ "input": []*proto3pb.TestAllTypes{}, }, }, @@ -354,7 +354,7 @@ func TestRuntimeCost(t *testing.T) { decls: []*exprpb.Decl{decls.NewVar("input", nestedList)}, expr: `input.all(x, x.all(y, true))`, want: 2, - in: map[string]interface{}{ + in: map[string]any{ "input": []*proto3pb.TestAllTypes{}, }, }, @@ -368,7 +368,7 @@ func TestRuntimeCost(t *testing.T) { decls: []*exprpb.Decl{decls.NewVar("input", decls.String)}, expr: `input.matches('[0-9]')`, want: 103, - in: map[string]interface{}{"input": string(randSeq(500))}, + in: map[string]any{"input": string(randSeq(500))}, }, { name: "variable cost function with constant", @@ -470,14 +470,14 @@ func TestRuntimeCost(t *testing.T) { decls: []*exprpb.Decl{decls.NewVar("input", decls.Bytes)}, expr: `string(input)`, want: 51, - in: map[string]interface{}{"input": randSeq(500)}, + in: map[string]any{"input": randSeq(500)}, }, { name: "string to bytes conversion", decls: []*exprpb.Decl{decls.NewVar("input", decls.String)}, expr: `bytes(input)`, want: 51, - in: map[string]interface{}{"input": string(randSeq(500))}, + in: map[string]any{"input": string(randSeq(500))}, }, { name: "int to string conversion", @@ -492,7 +492,7 @@ func TestRuntimeCost(t *testing.T) { decls.NewVar("arg1", decls.String), }, want: 2502, - in: map[string]interface{}{"input": string(randSeq(500)), "arg1": string(randSeq(500))}, + in: map[string]any{"input": string(randSeq(500)), "arg1": string(randSeq(500))}, }, { name: "matches", @@ -501,7 +501,7 @@ func TestRuntimeCost(t *testing.T) { decls.NewVar("input", decls.String), }, want: 103, - in: map[string]interface{}{"input": string(randSeq(500)), "arg1": string(randSeq(500))}, + in: map[string]any{"input": string(randSeq(500)), "arg1": string(randSeq(500))}, }, { name: "startsWith", @@ -511,7 +511,7 @@ func TestRuntimeCost(t *testing.T) { decls.NewVar("arg1", decls.String), }, want: 3, - in: map[string]interface{}{"input": "idc", "arg1": string(randSeq(500))}, + in: map[string]any{"input": "idc", "arg1": string(randSeq(500))}, }, { name: "endsWith", @@ -521,7 +521,7 @@ func TestRuntimeCost(t *testing.T) { decls.NewVar("arg1", decls.String), }, want: 3, - in: map[string]interface{}{"input": "idc", "arg1": string(randSeq(500))}, + in: map[string]any{"input": "idc", "arg1": string(randSeq(500))}, }, { name: "size receiver", @@ -530,7 +530,7 @@ func TestRuntimeCost(t *testing.T) { decls.NewVar("input", decls.String), }, want: 2, - in: map[string]interface{}{"input": "500", "arg1": "500"}, + in: map[string]any{"input": "500", "arg1": "500"}, }, { name: "size", @@ -539,7 +539,7 @@ func TestRuntimeCost(t *testing.T) { decls.NewVar("input", decls.String), }, want: 2, - in: map[string]interface{}{"input": "500", "arg1": "500"}, + in: map[string]any{"input": "500", "arg1": "500"}, }, { name: "ternary eval", @@ -550,19 +550,19 @@ func TestRuntimeCost(t *testing.T) { decls.NewVar("input2", allList), }, want: 6, - in: map[string]interface{}{"input1": []*proto3pb.TestAllTypes{{}}, "input2": []*proto3pb.TestAllTypes{{}}, "x": 1}, + in: map[string]any{"input1": []*proto3pb.TestAllTypes{{}}, "input2": []*proto3pb.TestAllTypes{{}}, "x": 1}, }, { name: "ternary eval trivial, true", expr: `true ? false : 1 > 3`, want: 0, - in: map[string]interface{}{}, + in: map[string]any{}, }, { name: "ternary eval trivial, false", expr: `false ? false : 1 > 3`, want: 1, - in: map[string]interface{}{}, + in: map[string]any{}, }, { name: "comprehension over map", @@ -571,7 +571,7 @@ func TestRuntimeCost(t *testing.T) { decls.NewVar("input", allMap), }, want: 9, - in: map[string]interface{}{"input": map[string]interface{}{"val": &proto3pb.TestAllTypes{}}}, + in: map[string]any{"input": map[string]any{"val": &proto3pb.TestAllTypes{}}}, }, { name: "comprehension over nested map of maps", @@ -580,7 +580,7 @@ func TestRuntimeCost(t *testing.T) { decls.NewVar("input", nestedMap), }, want: 2, - in: map[string]interface{}{"input": map[string]interface{}{}}, + in: map[string]any{"input": map[string]any{}}, }, { name: "string size of map keys", @@ -589,7 +589,7 @@ func TestRuntimeCost(t *testing.T) { decls.NewVar("input", nestedMap), }, want: 2, - in: map[string]interface{}{"input": map[string]interface{}{}}, + in: map[string]any{"input": map[string]any{}}, }, { name: "comprehension variable shadowing", @@ -598,7 +598,7 @@ func TestRuntimeCost(t *testing.T) { decls.NewVar("input", nestedMap), }, want: 2, - in: map[string]interface{}{"input": map[string]interface{}{}}, + in: map[string]any{"input": map[string]any{}}, }, { name: "comprehension variable shadowing", @@ -607,7 +607,7 @@ func TestRuntimeCost(t *testing.T) { decls.NewVar("input", nestedMap), }, want: 2, - in: map[string]interface{}{"input": map[string]interface{}{}}, + in: map[string]any{"input": map[string]any{}}, }, { name: "list concat", @@ -617,7 +617,7 @@ func TestRuntimeCost(t *testing.T) { decls.NewVar("list2", decls.NewListType(decls.Int)), }, want: 4, - in: map[string]interface{}{"list1": []int{}, "list2": []int{}}, + in: map[string]any{"list1": []int{}, "list2": []int{}}, }, { name: "str concat", @@ -627,7 +627,7 @@ func TestRuntimeCost(t *testing.T) { decls.NewVar("str2", decls.String), }, want: 6, - in: map[string]interface{}{"str1": "val1", "str2": "val2222222"}, + in: map[string]any{"str1": "val1", "str2": "val2222222"}, }, { name: "at limit", @@ -636,7 +636,7 @@ func TestRuntimeCost(t *testing.T) { decls.NewVar("str1", decls.String), decls.NewVar("str2", decls.String), }, - in: map[string]interface{}{"str1": "val1", "str2": "val2222222"}, + in: map[string]any{"str1": "val1", "str2": "val2222222"}, limit: 6, want: 6, }, @@ -647,7 +647,7 @@ func TestRuntimeCost(t *testing.T) { decls.NewVar("str1", decls.String), decls.NewVar("str2", decls.String), }, - in: map[string]interface{}{"str1": "val1", "str2": "val2222222"}, + in: map[string]any{"str1": "val1", "str2": "val2222222"}, limit: 5, expectExceedsLimit: true, }, @@ -655,21 +655,21 @@ func TestRuntimeCost(t *testing.T) { name: "ternary as operand", expr: `(1 > 2 ? 5 : 3) > 1`, decls: []*exprpb.Decl{}, - in: map[string]interface{}{}, + in: map[string]any{}, want: 2, }, { name: "ternary as operand", expr: `(1 > 2 || 2 > 1) == true`, decls: []*exprpb.Decl{}, - in: map[string]interface{}{}, + in: map[string]any{}, want: 3, }, { name: "list map literal", expr: `[{'k1': 1}, {'k2': 2}].all(x, true)`, decls: []*exprpb.Decl{}, - in: map[string]interface{}{}, + in: map[string]any{}, want: 77, }, } diff --git a/repl/commands.go b/repl/commands.go index 77c9db37..3522b00c 100644 --- a/repl/commands.go +++ b/repl/commands.go @@ -159,7 +159,7 @@ func Parse(line string) (Cmder, error) { // ANTLR interface implementations // Implement antlr ErrorListener interface for syntax errors. -func (c *commandParseListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line, column int, msg string, e antlr.RecognitionException) { +func (c *commandParseListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol any, line, column int, msg string, e antlr.RecognitionException) { c.errs = append(c.errs, fmt.Errorf("(%d:%d) %s", line, column, msg)) } diff --git a/repl/evaluator.go b/repl/evaluator.go index 42e79b66..d4b19ff5 100644 --- a/repl/evaluator.go +++ b/repl/evaluator.go @@ -130,7 +130,7 @@ func (l *letFunction) updateImpl(env *cel.Env, deps []*functions.Overload) error return types.NewErr("error evaluating %s: %v", l, err) } - activation := make(map[string]interface{}) + activation := make(map[string]any) for i, param := range l.params { activation[param.identifier] = args[i] } @@ -629,7 +629,7 @@ func (e *Evaluator) Status() string { // returns the environment for compiling and planning the top level CEL expression and an activation with the // values of the let expressions. func (e *Evaluator) applyContext() (*cel.Env, interpreter.Activation, error) { - var vars = make(map[string]interface{}) + var vars = make(map[string]any) for _, el := range e.ctx.letVars { if el.prog == nil { diff --git a/repl/parser/commands_base_visitor.go b/repl/parser/commands_base_visitor.go index 96a9c0af..5e8b8032 100644 --- a/repl/parser/commands_base_visitor.go +++ b/repl/parser/commands_base_visitor.go @@ -7,182 +7,182 @@ type BaseCommandsVisitor struct { *antlr.BaseParseTreeVisitor } -func (v *BaseCommandsVisitor) VisitStartCommand(ctx *StartCommandContext) interface{} { +func (v *BaseCommandsVisitor) VisitStartCommand(ctx *StartCommandContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitCommand(ctx *CommandContext) interface{} { +func (v *BaseCommandsVisitor) VisitCommand(ctx *CommandContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitLet(ctx *LetContext) interface{} { +func (v *BaseCommandsVisitor) VisitLet(ctx *LetContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitDeclare(ctx *DeclareContext) interface{} { +func (v *BaseCommandsVisitor) VisitDeclare(ctx *DeclareContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitVarDecl(ctx *VarDeclContext) interface{} { +func (v *BaseCommandsVisitor) VisitVarDecl(ctx *VarDeclContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitFnDecl(ctx *FnDeclContext) interface{} { +func (v *BaseCommandsVisitor) VisitFnDecl(ctx *FnDeclContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitParam(ctx *ParamContext) interface{} { +func (v *BaseCommandsVisitor) VisitParam(ctx *ParamContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitDelete(ctx *DeleteContext) interface{} { +func (v *BaseCommandsVisitor) VisitDelete(ctx *DeleteContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitSimple(ctx *SimpleContext) interface{} { +func (v *BaseCommandsVisitor) VisitSimple(ctx *SimpleContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitEmpty(ctx *EmptyContext) interface{} { +func (v *BaseCommandsVisitor) VisitEmpty(ctx *EmptyContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitExprCmd(ctx *ExprCmdContext) interface{} { +func (v *BaseCommandsVisitor) VisitExprCmd(ctx *ExprCmdContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitQualId(ctx *QualIdContext) interface{} { +func (v *BaseCommandsVisitor) VisitQualId(ctx *QualIdContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitStartType(ctx *StartTypeContext) interface{} { +func (v *BaseCommandsVisitor) VisitStartType(ctx *StartTypeContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitType(ctx *TypeContext) interface{} { +func (v *BaseCommandsVisitor) VisitType(ctx *TypeContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitTypeId(ctx *TypeIdContext) interface{} { +func (v *BaseCommandsVisitor) VisitTypeId(ctx *TypeIdContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitTypeParamList(ctx *TypeParamListContext) interface{} { +func (v *BaseCommandsVisitor) VisitTypeParamList(ctx *TypeParamListContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitStart(ctx *StartContext) interface{} { +func (v *BaseCommandsVisitor) VisitStart(ctx *StartContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitExpr(ctx *ExprContext) interface{} { +func (v *BaseCommandsVisitor) VisitExpr(ctx *ExprContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitConditionalOr(ctx *ConditionalOrContext) interface{} { +func (v *BaseCommandsVisitor) VisitConditionalOr(ctx *ConditionalOrContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitConditionalAnd(ctx *ConditionalAndContext) interface{} { +func (v *BaseCommandsVisitor) VisitConditionalAnd(ctx *ConditionalAndContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitRelation(ctx *RelationContext) interface{} { +func (v *BaseCommandsVisitor) VisitRelation(ctx *RelationContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitCalc(ctx *CalcContext) interface{} { +func (v *BaseCommandsVisitor) VisitCalc(ctx *CalcContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitMemberExpr(ctx *MemberExprContext) interface{} { +func (v *BaseCommandsVisitor) VisitMemberExpr(ctx *MemberExprContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitLogicalNot(ctx *LogicalNotContext) interface{} { +func (v *BaseCommandsVisitor) VisitLogicalNot(ctx *LogicalNotContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitNegate(ctx *NegateContext) interface{} { +func (v *BaseCommandsVisitor) VisitNegate(ctx *NegateContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitSelectOrCall(ctx *SelectOrCallContext) interface{} { +func (v *BaseCommandsVisitor) VisitSelectOrCall(ctx *SelectOrCallContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitPrimaryExpr(ctx *PrimaryExprContext) interface{} { +func (v *BaseCommandsVisitor) VisitPrimaryExpr(ctx *PrimaryExprContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitIndex(ctx *IndexContext) interface{} { +func (v *BaseCommandsVisitor) VisitIndex(ctx *IndexContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitCreateMessage(ctx *CreateMessageContext) interface{} { +func (v *BaseCommandsVisitor) VisitCreateMessage(ctx *CreateMessageContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitIdentOrGlobalCall(ctx *IdentOrGlobalCallContext) interface{} { +func (v *BaseCommandsVisitor) VisitIdentOrGlobalCall(ctx *IdentOrGlobalCallContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitNested(ctx *NestedContext) interface{} { +func (v *BaseCommandsVisitor) VisitNested(ctx *NestedContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitCreateList(ctx *CreateListContext) interface{} { +func (v *BaseCommandsVisitor) VisitCreateList(ctx *CreateListContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitCreateStruct(ctx *CreateStructContext) interface{} { +func (v *BaseCommandsVisitor) VisitCreateStruct(ctx *CreateStructContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitConstantLiteral(ctx *ConstantLiteralContext) interface{} { +func (v *BaseCommandsVisitor) VisitConstantLiteral(ctx *ConstantLiteralContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitExprList(ctx *ExprListContext) interface{} { +func (v *BaseCommandsVisitor) VisitExprList(ctx *ExprListContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitFieldInitializerList(ctx *FieldInitializerListContext) interface{} { +func (v *BaseCommandsVisitor) VisitFieldInitializerList(ctx *FieldInitializerListContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitMapInitializerList(ctx *MapInitializerListContext) interface{} { +func (v *BaseCommandsVisitor) VisitMapInitializerList(ctx *MapInitializerListContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitInt(ctx *IntContext) interface{} { +func (v *BaseCommandsVisitor) VisitInt(ctx *IntContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitUint(ctx *UintContext) interface{} { +func (v *BaseCommandsVisitor) VisitUint(ctx *UintContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitDouble(ctx *DoubleContext) interface{} { +func (v *BaseCommandsVisitor) VisitDouble(ctx *DoubleContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitString(ctx *StringContext) interface{} { +func (v *BaseCommandsVisitor) VisitString(ctx *StringContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitBytes(ctx *BytesContext) interface{} { +func (v *BaseCommandsVisitor) VisitBytes(ctx *BytesContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitBoolTrue(ctx *BoolTrueContext) interface{} { +func (v *BaseCommandsVisitor) VisitBoolTrue(ctx *BoolTrueContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitBoolFalse(ctx *BoolFalseContext) interface{} { +func (v *BaseCommandsVisitor) VisitBoolFalse(ctx *BoolFalseContext) any { return v.VisitChildren(ctx) } -func (v *BaseCommandsVisitor) VisitNull(ctx *NullContext) interface{} { +func (v *BaseCommandsVisitor) VisitNull(ctx *NullContext) any { return v.VisitChildren(ctx) } diff --git a/repl/parser/commands_parser.go b/repl/parser/commands_parser.go index 669ae685..38aad1a5 100644 --- a/repl/parser/commands_parser.go +++ b/repl/parser/commands_parser.go @@ -411,7 +411,7 @@ func (s *StartCommandContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *StartCommandContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *StartCommandContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitStartCommand(s) @@ -611,7 +611,7 @@ func (s *CommandContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *CommandContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *CommandContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitCommand(s) @@ -844,7 +844,7 @@ func (s *LetContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *LetContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *LetContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitLet(s) @@ -1035,7 +1035,7 @@ func (s *DeclareContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *DeclareContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *DeclareContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitDeclare(s) @@ -1215,7 +1215,7 @@ func (s *VarDeclContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *VarDeclContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *VarDeclContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitVarDecl(s) @@ -1474,7 +1474,7 @@ func (s *FnDeclContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *FnDeclContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *FnDeclContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitFnDecl(s) @@ -1680,7 +1680,7 @@ func (s *ParamContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *ParamContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *ParamContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitParam(s) @@ -1848,7 +1848,7 @@ func (s *DeleteContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *DeleteContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *DeleteContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitDelete(s) @@ -2034,7 +2034,7 @@ func (s *SimpleContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *SimpleContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *SimpleContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitSimple(s) @@ -2174,7 +2174,7 @@ func (s *EmptyContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *EmptyContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *EmptyContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitEmpty(s) @@ -2297,7 +2297,7 @@ func (s *ExprCmdContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *ExprCmdContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *ExprCmdContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitExprCmd(s) @@ -2472,7 +2472,7 @@ func (s *QualIdContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *QualIdContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *QualIdContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitQualId(s) @@ -2643,7 +2643,7 @@ func (s *StartTypeContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *StartTypeContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *StartTypeContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitStartType(s) @@ -2804,7 +2804,7 @@ func (s *TypeContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *TypeContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *TypeContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitType(s) @@ -2986,7 +2986,7 @@ func (s *TypeIdContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *TypeIdContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *TypeIdContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitTypeId(s) @@ -3216,7 +3216,7 @@ func (s *TypeParamListContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *TypeParamListContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *TypeParamListContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitTypeParamList(s) @@ -3382,7 +3382,7 @@ func (s *StartContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *StartContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *StartContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitStart(s) @@ -3598,7 +3598,7 @@ func (s *ExprContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *ExprContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *ExprContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitExpr(s) @@ -3838,7 +3838,7 @@ func (s *ConditionalOrContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *ConditionalOrContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *ConditionalOrContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitConditionalOr(s) @@ -4072,7 +4072,7 @@ func (s *ConditionalAndContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *ConditionalAndContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *ConditionalAndContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitConditionalAnd(s) @@ -4298,7 +4298,7 @@ func (s *RelationContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *RelationContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *RelationContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitRelation(s) @@ -4545,7 +4545,7 @@ func (s *CalcContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *CalcContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *CalcContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitCalc(s) @@ -4797,7 +4797,7 @@ func (s *LogicalNotContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *LogicalNotContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *LogicalNotContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitLogicalNot(s) @@ -4853,7 +4853,7 @@ func (s *MemberExprContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *MemberExprContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *MemberExprContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitMemberExpr(s) @@ -4927,7 +4927,7 @@ func (s *NegateContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *NegateContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *NegateContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitNegate(s) @@ -5184,7 +5184,7 @@ func (s *SelectOrCallContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *SelectOrCallContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *SelectOrCallContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitSelectOrCall(s) @@ -5240,7 +5240,7 @@ func (s *PrimaryExprContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *PrimaryExprContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *PrimaryExprContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitPrimaryExpr(s) @@ -5330,7 +5330,7 @@ func (s *IndexContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *IndexContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *IndexContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitIndex(s) @@ -5424,7 +5424,7 @@ func (s *CreateMessageContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *CreateMessageContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *CreateMessageContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitCreateMessage(s) @@ -5748,7 +5748,7 @@ func (s *CreateListContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *CreateListContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *CreateListContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitCreateList(s) @@ -5826,7 +5826,7 @@ func (s *CreateStructContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *CreateStructContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *CreateStructContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitCreateStruct(s) @@ -5882,7 +5882,7 @@ func (s *ConstantLiteralContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *ConstantLiteralContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *ConstantLiteralContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitConstantLiteral(s) @@ -5951,7 +5951,7 @@ func (s *NestedContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *NestedContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *NestedContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitNested(s) @@ -6043,7 +6043,7 @@ func (s *IdentOrGlobalCallContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *IdentOrGlobalCallContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *IdentOrGlobalCallContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitIdentOrGlobalCall(s) @@ -6380,7 +6380,7 @@ func (s *ExprListContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *ExprListContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *ExprListContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitExprList(s) @@ -6641,7 +6641,7 @@ func (s *FieldInitializerListContext) ExitRule(listener antlr.ParseTreeListener) } } -func (s *FieldInitializerListContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *FieldInitializerListContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitFieldInitializerList(s) @@ -6915,7 +6915,7 @@ func (s *MapInitializerListContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *MapInitializerListContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *MapInitializerListContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitMapInitializerList(s) @@ -7108,7 +7108,7 @@ func (s *BytesContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *BytesContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *BytesContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitBytes(s) @@ -7157,7 +7157,7 @@ func (s *UintContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *UintContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *UintContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitUint(s) @@ -7206,7 +7206,7 @@ func (s *NullContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *NullContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *NullContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitNull(s) @@ -7255,7 +7255,7 @@ func (s *BoolFalseContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *BoolFalseContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *BoolFalseContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitBoolFalse(s) @@ -7304,7 +7304,7 @@ func (s *StringContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *StringContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *StringContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitString(s) @@ -7362,7 +7362,7 @@ func (s *DoubleContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *DoubleContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *DoubleContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitDouble(s) @@ -7411,7 +7411,7 @@ func (s *BoolTrueContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *BoolTrueContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *BoolTrueContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitBoolTrue(s) @@ -7469,7 +7469,7 @@ func (s *IntContext) ExitRule(listener antlr.ParseTreeListener) { } } -func (s *IntContext) Accept(visitor antlr.ParseTreeVisitor) interface{} { +func (s *IntContext) Accept(visitor antlr.ParseTreeVisitor) any { switch t := visitor.(type) { case CommandsVisitor: return t.VisitInt(s) diff --git a/repl/parser/commands_test.go b/repl/parser/commands_test.go index e9617532..8033d3b5 100644 --- a/repl/parser/commands_test.go +++ b/repl/parser/commands_test.go @@ -27,7 +27,7 @@ type errListener struct { errs []error } -func (l *errListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line, column int, msg string, e antlr.RecognitionException) { +func (l *errListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol any, line, column int, msg string, e antlr.RecognitionException) { l.errs = append(l.errs, fmt.Errorf("(%d:%d) %s", line, column, msg)) } diff --git a/repl/parser/commands_visitor.go b/repl/parser/commands_visitor.go index 1e3163b4..3e77a4af 100644 --- a/repl/parser/commands_visitor.go +++ b/repl/parser/commands_visitor.go @@ -8,137 +8,137 @@ type CommandsVisitor interface { antlr.ParseTreeVisitor // Visit a parse tree produced by CommandsParser#startCommand. - VisitStartCommand(ctx *StartCommandContext) interface{} + VisitStartCommand(ctx *StartCommandContext) any // Visit a parse tree produced by CommandsParser#command. - VisitCommand(ctx *CommandContext) interface{} + VisitCommand(ctx *CommandContext) any // Visit a parse tree produced by CommandsParser#let. - VisitLet(ctx *LetContext) interface{} + VisitLet(ctx *LetContext) any // Visit a parse tree produced by CommandsParser#declare. - VisitDeclare(ctx *DeclareContext) interface{} + VisitDeclare(ctx *DeclareContext) any // Visit a parse tree produced by CommandsParser#varDecl. - VisitVarDecl(ctx *VarDeclContext) interface{} + VisitVarDecl(ctx *VarDeclContext) any // Visit a parse tree produced by CommandsParser#fnDecl. - VisitFnDecl(ctx *FnDeclContext) interface{} + VisitFnDecl(ctx *FnDeclContext) any // Visit a parse tree produced by CommandsParser#param. - VisitParam(ctx *ParamContext) interface{} + VisitParam(ctx *ParamContext) any // Visit a parse tree produced by CommandsParser#delete. - VisitDelete(ctx *DeleteContext) interface{} + VisitDelete(ctx *DeleteContext) any // Visit a parse tree produced by CommandsParser#simple. - VisitSimple(ctx *SimpleContext) interface{} + VisitSimple(ctx *SimpleContext) any // Visit a parse tree produced by CommandsParser#empty. - VisitEmpty(ctx *EmptyContext) interface{} + VisitEmpty(ctx *EmptyContext) any // Visit a parse tree produced by CommandsParser#exprCmd. - VisitExprCmd(ctx *ExprCmdContext) interface{} + VisitExprCmd(ctx *ExprCmdContext) any // Visit a parse tree produced by CommandsParser#qualId. - VisitQualId(ctx *QualIdContext) interface{} + VisitQualId(ctx *QualIdContext) any // Visit a parse tree produced by CommandsParser#startType. - VisitStartType(ctx *StartTypeContext) interface{} + VisitStartType(ctx *StartTypeContext) any // Visit a parse tree produced by CommandsParser#type. - VisitType(ctx *TypeContext) interface{} + VisitType(ctx *TypeContext) any // Visit a parse tree produced by CommandsParser#typeId. - VisitTypeId(ctx *TypeIdContext) interface{} + VisitTypeId(ctx *TypeIdContext) any // Visit a parse tree produced by CommandsParser#typeParamList. - VisitTypeParamList(ctx *TypeParamListContext) interface{} + VisitTypeParamList(ctx *TypeParamListContext) any // Visit a parse tree produced by CommandsParser#start. - VisitStart(ctx *StartContext) interface{} + VisitStart(ctx *StartContext) any // Visit a parse tree produced by CommandsParser#expr. - VisitExpr(ctx *ExprContext) interface{} + VisitExpr(ctx *ExprContext) any // Visit a parse tree produced by CommandsParser#conditionalOr. - VisitConditionalOr(ctx *ConditionalOrContext) interface{} + VisitConditionalOr(ctx *ConditionalOrContext) any // Visit a parse tree produced by CommandsParser#conditionalAnd. - VisitConditionalAnd(ctx *ConditionalAndContext) interface{} + VisitConditionalAnd(ctx *ConditionalAndContext) any // Visit a parse tree produced by CommandsParser#relation. - VisitRelation(ctx *RelationContext) interface{} + VisitRelation(ctx *RelationContext) any // Visit a parse tree produced by CommandsParser#calc. - VisitCalc(ctx *CalcContext) interface{} + VisitCalc(ctx *CalcContext) any // Visit a parse tree produced by CommandsParser#MemberExpr. - VisitMemberExpr(ctx *MemberExprContext) interface{} + VisitMemberExpr(ctx *MemberExprContext) any // Visit a parse tree produced by CommandsParser#LogicalNot. - VisitLogicalNot(ctx *LogicalNotContext) interface{} + VisitLogicalNot(ctx *LogicalNotContext) any // Visit a parse tree produced by CommandsParser#Negate. - VisitNegate(ctx *NegateContext) interface{} + VisitNegate(ctx *NegateContext) any // Visit a parse tree produced by CommandsParser#SelectOrCall. - VisitSelectOrCall(ctx *SelectOrCallContext) interface{} + VisitSelectOrCall(ctx *SelectOrCallContext) any // Visit a parse tree produced by CommandsParser#PrimaryExpr. - VisitPrimaryExpr(ctx *PrimaryExprContext) interface{} + VisitPrimaryExpr(ctx *PrimaryExprContext) any // Visit a parse tree produced by CommandsParser#Index. - VisitIndex(ctx *IndexContext) interface{} + VisitIndex(ctx *IndexContext) any // Visit a parse tree produced by CommandsParser#CreateMessage. - VisitCreateMessage(ctx *CreateMessageContext) interface{} + VisitCreateMessage(ctx *CreateMessageContext) any // Visit a parse tree produced by CommandsParser#IdentOrGlobalCall. - VisitIdentOrGlobalCall(ctx *IdentOrGlobalCallContext) interface{} + VisitIdentOrGlobalCall(ctx *IdentOrGlobalCallContext) any // Visit a parse tree produced by CommandsParser#Nested. - VisitNested(ctx *NestedContext) interface{} + VisitNested(ctx *NestedContext) any // Visit a parse tree produced by CommandsParser#CreateList. - VisitCreateList(ctx *CreateListContext) interface{} + VisitCreateList(ctx *CreateListContext) any // Visit a parse tree produced by CommandsParser#CreateStruct. - VisitCreateStruct(ctx *CreateStructContext) interface{} + VisitCreateStruct(ctx *CreateStructContext) any // Visit a parse tree produced by CommandsParser#ConstantLiteral. - VisitConstantLiteral(ctx *ConstantLiteralContext) interface{} + VisitConstantLiteral(ctx *ConstantLiteralContext) any // Visit a parse tree produced by CommandsParser#exprList. - VisitExprList(ctx *ExprListContext) interface{} + VisitExprList(ctx *ExprListContext) any // Visit a parse tree produced by CommandsParser#fieldInitializerList. - VisitFieldInitializerList(ctx *FieldInitializerListContext) interface{} + VisitFieldInitializerList(ctx *FieldInitializerListContext) any // Visit a parse tree produced by CommandsParser#mapInitializerList. - VisitMapInitializerList(ctx *MapInitializerListContext) interface{} + VisitMapInitializerList(ctx *MapInitializerListContext) any // Visit a parse tree produced by CommandsParser#Int. - VisitInt(ctx *IntContext) interface{} + VisitInt(ctx *IntContext) any // Visit a parse tree produced by CommandsParser#Uint. - VisitUint(ctx *UintContext) interface{} + VisitUint(ctx *UintContext) any // Visit a parse tree produced by CommandsParser#Double. - VisitDouble(ctx *DoubleContext) interface{} + VisitDouble(ctx *DoubleContext) any // Visit a parse tree produced by CommandsParser#String. - VisitString(ctx *StringContext) interface{} + VisitString(ctx *StringContext) any // Visit a parse tree produced by CommandsParser#Bytes. - VisitBytes(ctx *BytesContext) interface{} + VisitBytes(ctx *BytesContext) any // Visit a parse tree produced by CommandsParser#BoolTrue. - VisitBoolTrue(ctx *BoolTrueContext) interface{} + VisitBoolTrue(ctx *BoolTrueContext) any // Visit a parse tree produced by CommandsParser#BoolFalse. - VisitBoolFalse(ctx *BoolFalseContext) interface{} + VisitBoolFalse(ctx *BoolFalseContext) any // Visit a parse tree produced by CommandsParser#Null. - VisitNull(ctx *NullContext) interface{} + VisitNull(ctx *NullContext) any } diff --git a/repl/typefmt.go b/repl/typefmt.go index 46193407..397d1ba9 100644 --- a/repl/typefmt.go +++ b/repl/typefmt.go @@ -114,7 +114,7 @@ type errorListener struct { errs []error } -func (l *errorListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol interface{}, line, column int, msg string, e antlr.RecognitionException) { +func (l *errorListener) SyntaxError(recognizer antlr.Recognizer, offendingSymbol any, line, column int, msg string, e antlr.RecognitionException) { l.errs = append(l.errs, fmt.Errorf("type parse error: %s", msg)) l.DefaultErrorListener.SyntaxError(recognizer, offendingSymbol, line, column, msg, e) } @@ -129,7 +129,7 @@ var _ parser.CommandsVisitor = &typesVisitor{} type typeParams []*exprpb.Type -func (t *typesVisitor) Visit(tree antlr.ParseTree) interface{} { +func (t *typesVisitor) Visit(tree antlr.ParseTree) any { switch ctx := tree.(type) { case *parser.StartTypeContext: return t.VisitStartType(ctx) @@ -146,7 +146,7 @@ func (t *typesVisitor) Visit(tree antlr.ParseTree) interface{} { } -func (t *typesVisitor) VisitStartType(ctx *parser.StartTypeContext) interface{} { +func (t *typesVisitor) VisitStartType(ctx *parser.StartTypeContext) any { return t.Visit(ctx.GetT()) } @@ -168,7 +168,7 @@ func checkWellKnown(name string) *exprpb.Type { return nil } -func (t *typesVisitor) VisitTypeId(ctx *parser.TypeIdContext) interface{} { +func (t *typesVisitor) VisitTypeId(ctx *parser.TypeIdContext) any { id := "" if ctx.GetLeadingDot() != nil { id += "." @@ -184,7 +184,7 @@ func (t *typesVisitor) VisitTypeId(ctx *parser.TypeIdContext) interface{} { return id } -func (t *typesVisitor) VisitTypeParamList(ctx *parser.TypeParamListContext) interface{} { +func (t *typesVisitor) VisitTypeParamList(ctx *parser.TypeParamListContext) any { var params typeParams for _, ty := range ctx.GetTypes() { p := t.Visit(ty) @@ -193,7 +193,7 @@ func (t *typesVisitor) VisitTypeParamList(ctx *parser.TypeParamListContext) inte return params } -func (t *typesVisitor) VisitType(ctx *parser.TypeContext) interface{} { +func (t *typesVisitor) VisitType(ctx *parser.TypeContext) any { emptyType := &exprpb.Type{} r := t.Visit(ctx.GetId()) diff --git a/server/server.go b/server/server.go index e5e18f04..ea687fad 100644 --- a/server/server.go +++ b/server/server.go @@ -112,7 +112,7 @@ func (s *ConformanceServer) Eval(ctx context.Context, in *confpb.EvalRequest) (* default: return nil, invalidArgument("No expression.") } - args := make(map[string]interface{}) + args := make(map[string]any) for name, exprValue := range in.Bindings { refVal, err := ExprValueToRefValue(env.TypeAdapter(), exprValue) if err != nil {