From a763b98723bb25e9ecdf52883612833d5264e829 Mon Sep 17 00:00:00 2001 From: TristonianJones Date: Thu, 15 Jun 2023 16:24:59 -0700 Subject: [PATCH 1/2] Unify decls.Type with types.Type --- cel/decls.go | 86 +++--- common/decls/BUILD.bazel | 2 - common/decls/decls.go | 40 +-- common/decls/decls_test.go | 211 +++++++++------ common/stdlib/standard.go | 362 +++++++++++++------------- common/types/BUILD.bazel | 5 +- common/types/bool.go | 6 - common/types/bytes.go | 7 - common/types/double.go | 10 - common/types/duration.go | 9 - common/types/int.go | 11 - common/types/list.go | 10 - common/types/map.go | 9 - common/types/null.go | 2 - common/types/provider.go | 5 + common/types/string.go | 9 - common/types/timestamp.go | 10 - common/types/type.go | 102 -------- common/{decls => types}/types.go | 16 +- common/{decls => types}/types_test.go | 175 +------------ common/types/uint.go | 10 - common/types/unknown.go | 5 - 22 files changed, 406 insertions(+), 696 deletions(-) delete mode 100644 common/types/type.go rename common/{decls => types}/types.go (98%) rename common/{decls => types}/types_test.go (76%) diff --git a/cel/decls.go b/cel/decls.go index c4601af8..64ccfaba 100644 --- a/cel/decls.go +++ b/cel/decls.go @@ -27,109 +27,109 @@ import ( ) // Kind indicates a CEL type's kind which is used to differentiate quickly between simple and complex types. -type Kind = decls.Kind +type Kind = types.Kind const ( // DynKind represents a dynamic type. This kind only exists at type-check time. - DynKind Kind = decls.DynKind + DynKind Kind = types.DynKind // AnyKind represents a google.protobuf.Any type. This kind only exists at type-check time. - AnyKind = decls.AnyKind + AnyKind = types.AnyKind // BoolKind represents a boolean type. - BoolKind = decls.BoolKind + BoolKind = types.BoolKind // BytesKind represents a bytes type. - BytesKind = decls.BytesKind + BytesKind = types.BytesKind // DoubleKind represents a double type. - DoubleKind = decls.DoubleKind + DoubleKind = types.DoubleKind // DurationKind represents a CEL duration type. - DurationKind = decls.DurationKind + DurationKind = types.DurationKind // IntKind represents an integer type. - IntKind = decls.IntKind + IntKind = types.IntKind // ListKind represents a list type. - ListKind = decls.ListKind + ListKind = types.ListKind // MapKind represents a map type. - MapKind = decls.MapKind + MapKind = types.MapKind // NullTypeKind represents a null type. - NullTypeKind = decls.NullTypeKind + NullTypeKind = types.NullTypeKind // OpaqueKind represents an abstract type which has no accessible fields. - OpaqueKind = decls.OpaqueKind + OpaqueKind = types.OpaqueKind // StringKind represents a string type. - StringKind = decls.StringKind + StringKind = types.StringKind // StructKind represents a structured object with typed fields. - StructKind = decls.StructKind + StructKind = types.StructKind // TimestampKind represents a a CEL time type. - TimestampKind = decls.TimestampKind + TimestampKind = types.TimestampKind // TypeKind represents the CEL type. - TypeKind = decls.TypeKind + TypeKind = types.TypeKind // TypeParamKind represents a parameterized type whose type name will be resolved at type-check time, if possible. - TypeParamKind = decls.TypeParamKind + TypeParamKind = types.TypeParamKind // UintKind represents a uint type. - UintKind = decls.UintKind + UintKind = types.UintKind ) var ( // AnyType represents the google.protobuf.Any type. - AnyType = decls.AnyType + AnyType = types.AnyType // BoolType represents the bool type. - BoolType = decls.BoolType + BoolType = types.BoolType // BytesType represents the bytes type. - BytesType = decls.BytesType + BytesType = types.BytesType // DoubleType represents the double type. - DoubleType = decls.DoubleType + DoubleType = types.DoubleType // DurationType represents the CEL duration type. - DurationType = decls.DurationType + DurationType = types.DurationType // DynType represents a dynamic CEL type whose type will be determined at runtime from context. - DynType = decls.DynType + DynType = types.DynType // IntType represents the int type. - IntType = decls.IntType + IntType = types.IntType // NullType represents the type of a null value. - NullType = decls.NullType + NullType = types.NullType // StringType represents the string type. - StringType = decls.StringType + StringType = types.StringType // TimestampType represents the time type. - TimestampType = decls.TimestampType + TimestampType = types.TimestampType // TypeType represents a CEL type - TypeType = decls.TypeType + TypeType = types.TypeType // UintType represents a uint type. - UintType = decls.UintType + UintType = types.UintType // function references for instantiating new types. // ListType creates an instances of a list type value with the provided element type. - ListType = decls.NewListType + ListType = types.NewListType // MapType creates an instance of a map type value with the provided key and value types. - MapType = decls.NewMapType + MapType = types.NewMapType // NullableType creates an instance of a nullable type with the provided wrapped type. // // Note: only primitive types are supported as wrapped types. - NullableType = decls.NewNullableType + NullableType = types.NewNullableType // OptionalType creates an abstract parameterized type instance corresponding to CEL's notion of optional. - OptionalType = decls.NewOptionalType + OptionalType = types.NewOptionalType // OpaqueType creates an abstract parameterized type with a given name. - OpaqueType = decls.NewOpaqueType + OpaqueType = types.NewOpaqueType // ObjectType creates a type references to an externally defined type, e.g. a protobuf message type. - ObjectType = decls.NewObjectType + ObjectType = types.NewObjectType // TypeParamType creates a parameterized type instance. - TypeParamType = decls.NewTypeParamType + TypeParamType = types.NewTypeParamType ) // Type holds a reference to a runtime type with an optional type-checked set of type parameters. -type Type = decls.Type +type Type = types.Type // Variable creates an instance of a variable declaration with a variable name and type. func Variable(name string, t *Type) EnvOption { @@ -298,12 +298,12 @@ func OverloadOperandTrait(trait int) OverloadOpt { // TypeToExprType converts a CEL-native type representation to a protobuf CEL Type representation. func TypeToExprType(t *Type) (*exprpb.Type, error) { - return decls.TypeToExprType(t) + return types.TypeToExprType(t) } // ExprTypeToType converts a protobuf CEL type representation to a CEL-native type representation. func ExprTypeToType(t *exprpb.Type) (*Type, error) { - return decls.ExprTypeToType(t) + return types.ExprTypeToType(t) } // ExprDeclToDeclaration converts a protobuf CEL declaration to a CEL-native declaration, either a Variable or Function. @@ -315,13 +315,13 @@ func ExprDeclToDeclaration(d *exprpb.Decl) (EnvOption, error) { for i, o := range overloads { args := make([]*Type, len(o.GetParams())) for j, p := range o.GetParams() { - a, err := decls.ExprTypeToType(p) + a, err := types.ExprTypeToType(p) if err != nil { return nil, err } args[j] = a } - res, err := decls.ExprTypeToType(o.GetResultType()) + res, err := types.ExprTypeToType(o.GetResultType()) if err != nil { return nil, err } @@ -329,7 +329,7 @@ func ExprDeclToDeclaration(d *exprpb.Decl) (EnvOption, error) { } return Function(d.GetName(), opts...), nil case *exprpb.Decl_Ident: - t, err := decls.ExprTypeToType(d.GetIdent().GetType()) + t, err := types.ExprTypeToType(d.GetIdent().GetType()) if err != nil { return nil, err } diff --git a/common/decls/BUILD.bazel b/common/decls/BUILD.bazel index f0643d3a..17791dce 100644 --- a/common/decls/BUILD.bazel +++ b/common/decls/BUILD.bazel @@ -9,7 +9,6 @@ go_library( name = "go_default_library", srcs = [ "decls.go", - "types.go", ], importpath = "github.com/google/cel-go/common/decls", deps = [ @@ -26,7 +25,6 @@ go_test( name = "go_default_test", srcs = [ "decls_test.go", - "types_test.go", ], embed = [":go_default_library"], deps = [ diff --git a/common/decls/decls.go b/common/decls/decls.go index 8472ffe0..47fcb30e 100644 --- a/common/decls/decls.go +++ b/common/decls/decls.go @@ -365,7 +365,9 @@ func SingletonFunctionBinding(fn functions.FunctionOp, traits ...int) FunctionOp // // Note: function bindings should be commonly configured with Overload instances whereas operand traits and // strict-ness should be rare occurrences. -func Overload(overloadID string, args []*Type, resultType *Type, opts ...OverloadOpt) FunctionOpt { +func Overload(overloadID string, + args []*types.Type, resultType *types.Type, + opts ...OverloadOpt) FunctionOpt { return newOverload(overloadID, false, args, resultType, opts...) } @@ -375,11 +377,15 @@ func Overload(overloadID string, args []*Type, resultType *Type, opts ...Overloa // // Note: function bindings should be commonly configured with Overload instances whereas operand traits and // strict-ness should be rare occurrences. -func MemberOverload(overloadID string, args []*Type, resultType *Type, opts ...OverloadOpt) FunctionOpt { +func MemberOverload(overloadID string, + args []*types.Type, resultType *types.Type, + opts ...OverloadOpt) FunctionOpt { return newOverload(overloadID, true, args, resultType, opts...) } -func newOverload(overloadID string, memberFunction bool, args []*Type, resultType *Type, opts ...OverloadOpt) FunctionOpt { +func newOverload(overloadID string, + memberFunction bool, args []*types.Type, resultType *types.Type, + opts ...OverloadOpt) FunctionOpt { return func(f *FunctionDecl) (*FunctionDecl, error) { overload, err := newOverloadInternal(overloadID, memberFunction, args, resultType, opts...) if err != nil { @@ -393,7 +399,9 @@ func newOverload(overloadID string, memberFunction bool, args []*Type, resultTyp } } -func newOverloadInternal(overloadID string, memberFunction bool, args []*Type, resultType *Type, opts ...OverloadOpt) (*OverloadDecl, error) { +func newOverloadInternal(overloadID string, + memberFunction bool, args []*types.Type, resultType *types.Type, + opts ...OverloadOpt) (*OverloadDecl, error) { overload := &OverloadDecl{ ID: overloadID, ArgTypes: args, @@ -424,10 +432,10 @@ type OverloadDecl struct { // ArgTypes contains the set of argument types expected by the overload. // // For member functions ArgTypes[0] represents the member operand type. - ArgTypes []*Type + ArgTypes []*types.Type // ResultType indicates the output type from calling the function. - ResultType *Type + ResultType *types.Type // IsMemberFunction indicates whether the overload is a member function IsMemberFunction bool @@ -558,7 +566,7 @@ func (o *OverloadDecl) matchesRuntimeSignature(disableTypeGuards bool, args ...r return matchOperandTrait(o.OperandTrait, args[0]) } -func matchRuntimeArgType(nonStrict, disableTypeGuards bool, argType *Type, arg ref.Val) bool { +func matchRuntimeArgType(nonStrict, disableTypeGuards bool, argType *types.Type, arg ref.Val) bool { if nonStrict && (disableTypeGuards || types.IsUnknownOrError(arg)) { return true } @@ -637,14 +645,14 @@ func OverloadOperandTrait(trait int) OverloadOpt { } // NewVariable creates a new variable declaration. -func NewVariable(name string, t *Type) *VariableDecl { +func NewVariable(name string, t *types.Type) *VariableDecl { return &VariableDecl{Name: name, Type: t} } // VariableDecl defines a variable declaration which may optionally have a constant value. type VariableDecl struct { Name string - Type *Type + Type *types.Type } // DeclarationEquals returns true if one variable declaration has the same name and same type as the input. @@ -657,7 +665,7 @@ func (v *VariableDecl) DeclarationEquals(other *VariableDecl) bool { // VariableDeclToExprDecl converts a go-native variable declaration into a protobuf-type variable declaration. func VariableDeclToExprDecl(v *VariableDecl) (*exprpb.Decl, error) { - varType, err := TypeToExprType(v.Type) + varType, err := types.TypeToExprType(v.Type) if err != nil { return nil, err } @@ -665,8 +673,8 @@ func VariableDeclToExprDecl(v *VariableDecl) (*exprpb.Decl, error) { } // TypeVariable creates a new type identifier for use within a ref.TypeProvider -func TypeVariable(t *Type) *VariableDecl { - return NewVariable(t.TypeName(), NewTypeTypeWithParam(t)) +func TypeVariable(t *types.Type) *VariableDecl { + return NewVariable(t.TypeName(), types.NewTypeTypeWithParam(t)) } // FunctionDeclToExprDecl converts a go-native function declaration into a protobuf-typed function declaration. @@ -678,14 +686,14 @@ func FunctionDeclToExprDecl(f *FunctionDecl) (*exprpb.Decl, error) { argTypes := make([]*exprpb.Type, len(o.ArgTypes)) for j, a := range o.ArgTypes { collectParamNames(paramNames, a) - at, err := TypeToExprType(a) + at, err := types.TypeToExprType(a) if err != nil { return nil, err } argTypes[j] = at } collectParamNames(paramNames, o.ResultType) - resultType, err := TypeToExprType(o.ResultType) + resultType, err := types.TypeToExprType(o.ResultType) if err != nil { return nil, err } @@ -710,8 +718,8 @@ func FunctionDeclToExprDecl(f *FunctionDecl) (*exprpb.Decl, error) { return chkdecls.NewFunction(f.Name, overloads...), nil } -func collectParamNames(paramNames map[string]struct{}, arg *Type) { - if arg.Kind == TypeParamKind { +func collectParamNames(paramNames map[string]struct{}, arg *types.Type) { + if arg.Kind == types.TypeParamKind { paramNames[arg.TypeName()] = struct{}{} } for _, param := range arg.Parameters { diff --git a/common/decls/decls_test.go b/common/decls/decls_test.go index 9ae1ff94..78fa4e33 100644 --- a/common/decls/decls_test.go +++ b/common/decls/decls_test.go @@ -31,7 +31,8 @@ import ( func TestFunctionBindings(t *testing.T) { sizeFunc, err := NewFunction("size", - MemberOverload("list_size", []*Type{NewListType(NewTypeParamType("T"))}, IntType), + MemberOverload("list_size", + []*types.Type{types.NewListType(types.NewTypeParamType("T"))}, types.IntType), ) if err != nil { t.Fatalf("NewFunction() failed: %v", err) @@ -44,7 +45,8 @@ func TestFunctionBindings(t *testing.T) { t.Errorf("sizeFunc.Bindings() produced %d bindings, wanted none", len(bindings)) } sizeFuncDef, err := NewFunction("size", - MemberOverload("list_size", []*Type{NewListType(NewTypeParamType("T"))}, IntType, + MemberOverload("list_size", + []*types.Type{types.NewListType(types.NewTypeParamType("T"))}, types.IntType, UnaryBinding(func(list ref.Val) ref.Val { sizer := list.(traits.Sizer) return sizer.Size() @@ -86,18 +88,21 @@ func TestFunctionVariableArgBindings(t *testing.T) { return types.DefaultTypeAdapter.NativeToValue(strings.SplitN(str, delim, int(count))) } splitFunc, err := NewFunction("split", - MemberOverload("string_split", []*Type{StringType}, NewListType(StringType), + MemberOverload("string_split", + []*types.Type{types.StringType}, types.NewListType(types.StringType), UnaryBinding(func(str ref.Val) ref.Val { s := str.(types.String) return splitImpl(string(s), "", -1) })), - MemberOverload("string_split_string", []*Type{StringType, StringType}, NewListType(StringType), + MemberOverload("string_split_string", + []*types.Type{types.StringType, types.StringType}, types.NewListType(types.StringType), BinaryBinding(func(str, sep ref.Val) ref.Val { s := str.(types.String) delim := sep.(types.String) return splitImpl(string(s), string(delim), -1) })), - MemberOverload("string_split_string_int", []*Type{StringType, StringType, IntType}, NewListType(StringType), + MemberOverload("string_split_string_int", + []*types.Type{types.StringType, types.StringType, types.IntType}, types.NewListType(types.StringType), FunctionBinding(func(args ...ref.Val) ref.Val { s := args[0].(types.String) delim := args[1].(types.String) @@ -168,7 +173,7 @@ func TestFunctionVariableArgBindings(t *testing.T) { func TestFunctionZeroArityBinding(t *testing.T) { now := types.DefaultTypeAdapter.NativeToValue(time.UnixMilli(1000)) nowFunc, err := NewFunction("now", - Overload("now", []*Type{}, TimestampType, + Overload("now", []*types.Type{}, types.TimestampType, FunctionBinding(func(args ...ref.Val) ref.Val { return now })), @@ -196,12 +201,18 @@ func TestFunctionSingletonBinding(t *testing.T) { // doesn't actually give much additional benefit. The drawback is that invalid signatures // at type-check might be valid at runtime. DisableTypeGuards(true), - Overload("size_map", []*Type{NewMapType(NewTypeParamType("K"), NewTypeParamType("V"))}, IntType), - Overload("size_list", []*Type{NewListType(NewTypeParamType("V"))}, IntType), - Overload("size_string", []*Type{StringType}, IntType), - MemberOverload("map_size", []*Type{NewMapType(NewTypeParamType("K"), NewTypeParamType("V"))}, IntType), - MemberOverload("list_size", []*Type{NewListType(NewTypeParamType("V"))}, IntType), - MemberOverload("string_size", []*Type{StringType}, IntType), + Overload("size_map", + []*types.Type{types.NewMapType(types.NewTypeParamType("K"), types.NewTypeParamType("V"))}, types.IntType), + Overload("size_list", + []*types.Type{types.NewListType(types.NewTypeParamType("V"))}, types.IntType), + Overload("size_string", + []*types.Type{types.StringType}, types.IntType), + MemberOverload("map_size", + []*types.Type{types.NewMapType(types.NewTypeParamType("K"), types.NewTypeParamType("V"))}, types.IntType), + MemberOverload("list_size", + []*types.Type{types.NewListType(types.NewTypeParamType("V"))}, types.IntType), + MemberOverload("string_size", + []*types.Type{types.StringType}, types.IntType), SingletonUnaryBinding(func(arg ref.Val) ref.Val { return arg.(traits.Sizer).Size() }, traits.SizerType), @@ -232,8 +243,10 @@ func TestFunctionSingletonBinding(t *testing.T) { func TestFunctionMerge(t *testing.T) { sizeFunc, err := NewFunction("size", - MemberOverload("list_size", []*Type{NewListType(NewTypeParamType("T"))}, IntType), - MemberOverload("map_size", []*Type{NewMapType(NewTypeParamType("K"), NewTypeParamType("V"))}, IntType), + MemberOverload("list_size", + []*types.Type{types.NewListType(types.NewTypeParamType("T"))}, types.IntType), + MemberOverload("map_size", + []*types.Type{types.NewMapType(types.NewTypeParamType("K"), types.NewTypeParamType("V"))}, types.IntType), ) if err != nil { t.Fatalf("NewFunction() failed: %v", err) @@ -246,7 +259,8 @@ func TestFunctionMerge(t *testing.T) { t.Errorf("sizeFunc.Merge(sizeFunc) != sizeFunc: %v", out) } sizeVecFunc, err := NewFunction("size", - MemberOverload("vector_size", []*Type{NewOpaqueType("vector", NewTypeParamType("T"))}, IntType), + MemberOverload("vector_size", + []*types.Type{types.NewOpaqueType("vector", types.NewTypeParamType("T"))}, types.IntType), SingletonUnaryBinding(func(sizer ref.Val) ref.Val { return sizer.(traits.Sizer).Size() }, traits.SizerType), @@ -279,13 +293,15 @@ func TestFunctionMerge(t *testing.T) { func TestFunctionMergeWrongName(t *testing.T) { sizeFunc, err := NewFunction("size", - MemberOverload("list_size", []*Type{NewListType(NewTypeParamType("T"))}, IntType), + MemberOverload("list_size", + []*types.Type{types.NewListType(types.NewTypeParamType("T"))}, types.IntType), ) if err != nil { t.Fatalf("NewFunction() failed: %v", err) } sizeVecFunc, err := NewFunction("sizeN", - MemberOverload("vector_size", []*Type{NewOpaqueType("vector", NewTypeParamType("T"))}, IntType), + MemberOverload("vector_size", + []*types.Type{types.NewOpaqueType("vector", types.NewTypeParamType("T"))}, types.IntType), ) if err != nil { t.Fatalf("NewFunction() failed: %v", err) @@ -298,13 +314,15 @@ func TestFunctionMergeWrongName(t *testing.T) { func TestFunctionMergeOverloadCollision(t *testing.T) { sizeFunc, err := NewFunction("size", - MemberOverload("list_size", []*Type{NewListType(NewTypeParamType("T"))}, IntType), + MemberOverload("list_size", + []*types.Type{types.NewListType(types.NewTypeParamType("T"))}, types.IntType), ) if err != nil { t.Fatalf("NewFunction() failed: %v", err) } sizeVecFunc, err := NewFunction("size", - MemberOverload("list_size2", []*Type{NewListType(NewTypeParamType("K"))}, IntType), + MemberOverload("list_size2", + []*types.Type{types.NewListType(types.NewTypeParamType("K"))}, types.IntType), ) if err != nil { t.Fatalf("NewFunction() failed: %v", err) @@ -317,13 +335,15 @@ func TestFunctionMergeOverloadCollision(t *testing.T) { func TestFunctionMergeOverloadArgCountRedefinition(t *testing.T) { sizeFunc, err := NewFunction("size", - MemberOverload("list_size", []*Type{NewListType(NewTypeParamType("T"))}, IntType), + MemberOverload("list_size", + []*types.Type{types.NewListType(types.NewTypeParamType("T"))}, types.IntType), ) if err != nil { t.Fatalf("NewFunction() failed: %v", err) } sizeVecFunc, err := NewFunction("size", - MemberOverload("list_size", []*Type{NewListType(NewTypeParamType("T")), IntType}, IntType), + MemberOverload("list_size", + []*types.Type{types.NewListType(types.NewTypeParamType("T")), types.IntType}, types.IntType), ) if err != nil { t.Fatalf("NewFunction() failed: %v", err) @@ -336,13 +356,15 @@ func TestFunctionMergeOverloadArgCountRedefinition(t *testing.T) { func TestFunctionMergeOverloadArgTypeRedefinition(t *testing.T) { sizeFunc, err := NewFunction("size", - MemberOverload("arg_size", []*Type{NewListType(NewTypeParamType("T"))}, IntType), + MemberOverload("arg_size", + []*types.Type{types.NewListType(types.NewTypeParamType("T"))}, types.IntType), ) if err != nil { t.Fatalf("NewFunction() failed: %v", err) } sizeVecFunc, err := NewFunction("size", - MemberOverload("arg_size", []*Type{NewMapType(IntType, StringType)}, IntType), + MemberOverload("arg_size", + []*types.Type{types.NewMapType(types.IntType, types.StringType)}, types.IntType), ) if err != nil { t.Fatalf("NewFunction() failed: %v", err) @@ -355,7 +377,8 @@ func TestFunctionMergeOverloadArgTypeRedefinition(t *testing.T) { func TestFunctionMergeSingletonRedefinition(t *testing.T) { sizeFunc, err := NewFunction("size", - MemberOverload("list_size", []*Type{NewListType(NewTypeParamType("T"))}, IntType), + MemberOverload("list_size", + []*types.Type{types.NewListType(types.NewTypeParamType("T"))}, types.IntType), SingletonUnaryBinding(func(ref.Val) ref.Val { return types.IntZero }), @@ -364,7 +387,8 @@ func TestFunctionMergeSingletonRedefinition(t *testing.T) { t.Fatalf("NewFunction() failed: %v", err) } sizeVecFunc, err := NewFunction("size", - MemberOverload("string_size", []*Type{StringType}, IntType), + MemberOverload("string_size", + []*types.Type{types.StringType}, types.IntType), SingletonUnaryBinding(func(ref.Val) ref.Val { return types.IntZero }), @@ -380,8 +404,8 @@ func TestFunctionMergeSingletonRedefinition(t *testing.T) { func TestFunctionAddDuplicateOverloads(t *testing.T) { _, err := NewFunction("max", - Overload("max_int", []*Type{IntType}, IntType), - Overload("max_int", []*Type{IntType}, IntType), + Overload("max_int", []*types.Type{types.IntType}, types.IntType), + Overload("max_int", []*types.Type{types.IntType}, types.IntType), ) if err != nil { t.Fatalf("NewFunction() with duplicate overload signature failed: %v", err) @@ -390,8 +414,8 @@ func TestFunctionAddDuplicateOverloads(t *testing.T) { func TestFunctionAddCollidingOverloads(t *testing.T) { _, err := NewFunction("max", - Overload("max_int", []*Type{IntType}, IntType), - Overload("max_int2", []*Type{IntType}, IntType), + Overload("max_int", []*types.Type{types.IntType}, types.IntType), + Overload("max_int2", []*types.Type{types.IntType}, types.IntType), ) if err == nil || !strings.Contains(err.Error(), "max_int collides with max_int2") { t.Fatalf("NewFunction() got %v, wanted collision error", err) @@ -409,7 +433,7 @@ func TestFunctionNoOverloads(t *testing.T) { func TestSingletonOverloadCollision(t *testing.T) { fn, err := NewFunction("id", - Overload("id_any", []*Type{AnyType}, AnyType, + Overload("id_any", []*types.Type{types.AnyType}, types.AnyType, UnaryBinding(func(arg ref.Val) ref.Val { return arg }), @@ -429,7 +453,7 @@ func TestSingletonOverloadCollision(t *testing.T) { func TestSingletonUnaryBindingRedefinition(t *testing.T) { _, err := NewFunction("id", - Overload("id_any", []*Type{AnyType}, AnyType), + Overload("id_any", []*types.Type{types.AnyType}, types.AnyType), SingletonUnaryBinding(func(arg ref.Val) ref.Val { return arg }), @@ -444,7 +468,7 @@ func TestSingletonUnaryBindingRedefinition(t *testing.T) { func TestSingletonBinaryBindingRedefinition(t *testing.T) { _, err := NewFunction("right", - Overload("right_double_double", []*Type{DoubleType, DoubleType}, DoubleType), + Overload("right_double_double", []*types.Type{types.DoubleType, types.DoubleType}, types.DoubleType), SingletonBinaryBinding(func(arg1, arg2 ref.Val) ref.Val { return arg2 }, traits.ComparerType), @@ -459,7 +483,7 @@ func TestSingletonBinaryBindingRedefinition(t *testing.T) { func TestSingletonFunctionBindingRedefinition(t *testing.T) { _, err := NewFunction("id", - Overload("id_any", []*Type{AnyType}, AnyType), + Overload("id_any", []*types.Type{types.AnyType}, types.AnyType), SingletonFunctionBinding(func(args ...ref.Val) ref.Val { return args[0] }, traits.ComparerType), @@ -474,7 +498,7 @@ func TestSingletonFunctionBindingRedefinition(t *testing.T) { func TestOverloadUnaryBindingRedefinition(t *testing.T) { _, err := NewFunction("id", - Overload("id_any", []*Type{AnyType}, AnyType, + Overload("id_any", []*types.Type{types.AnyType}, types.AnyType, UnaryBinding(func(arg ref.Val) ref.Val { return arg }), @@ -490,7 +514,7 @@ func TestOverloadUnaryBindingRedefinition(t *testing.T) { func TestOverloadUnaryBindingArgCountMismatch(t *testing.T) { _, err := NewFunction("id", - Overload("id_any", []*Type{}, AnyType, + Overload("id_any", []*types.Type{}, types.AnyType, UnaryBinding(func(arg ref.Val) ref.Val { return arg }), @@ -503,7 +527,7 @@ func TestOverloadUnaryBindingArgCountMismatch(t *testing.T) { func TestOverloadBinaryBindingArgCountMismatch(t *testing.T) { _, err := NewFunction("id", - Overload("id_any", []*Type{}, AnyType, + Overload("id_any", []*types.Type{}, types.AnyType, BinaryBinding(func(lhs, rhs ref.Val) ref.Val { return lhs }), @@ -516,7 +540,7 @@ func TestOverloadBinaryBindingArgCountMismatch(t *testing.T) { func TestOverloadBinaryBindingRedefinition(t *testing.T) { _, err := NewFunction("right", - Overload("right_double_double", []*Type{DoubleType, DoubleType}, DoubleType, + Overload("right_double_double", []*types.Type{types.DoubleType, types.DoubleType}, types.DoubleType, BinaryBinding(func(arg1, arg2 ref.Val) ref.Val { return arg2 }), @@ -532,7 +556,7 @@ func TestOverloadBinaryBindingRedefinition(t *testing.T) { func TestOverloadFunctionBindingRedefinition(t *testing.T) { _, err := NewFunction("id", - Overload("id_any", []*Type{AnyType}, AnyType, + Overload("id_any", []*types.Type{types.AnyType}, types.AnyType, FunctionBinding(func(args ...ref.Val) ref.Val { return args[0] }), @@ -549,12 +573,12 @@ func TestOverloadFunctionBindingRedefinition(t *testing.T) { func TestOverloadIsNonStrict(t *testing.T) { fn, err := NewFunction("getOrDefault", MemberOverload("get", - []*Type{NewMapType( - NewTypeParamType("K"), NewTypeParamType("V")), - NewTypeParamType("K"), - NewTypeParamType("V"), + []*types.Type{types.NewMapType( + types.NewTypeParamType("K"), types.NewTypeParamType("V")), + types.NewTypeParamType("K"), + types.NewTypeParamType("V"), }, - NewTypeParamType("V"), + types.NewTypeParamType("V"), OverloadOperandTrait(traits.ContainerType|traits.IndexerType), OverloadIsNonStrict(), FunctionBinding(func(args ...ref.Val) ref.Val { @@ -596,12 +620,12 @@ func TestOverloadIsNonStrict(t *testing.T) { func TestOverloadOperandTrait(t *testing.T) { fn, err := NewFunction("getOrDefault", MemberOverload("get", - []*Type{NewMapType( - NewTypeParamType("K"), NewTypeParamType("V")), - NewTypeParamType("K"), - NewTypeParamType("V"), + []*types.Type{types.NewMapType( + types.NewTypeParamType("K"), types.NewTypeParamType("V")), + types.NewTypeParamType("K"), + types.NewTypeParamType("V"), }, - NewTypeParamType("V"), + types.NewTypeParamType("V"), OverloadOperandTrait(traits.ContainerType|traits.IndexerType), FunctionBinding(func(args ...ref.Val) ref.Val { container := args[0].(traits.Container) @@ -641,8 +665,8 @@ func TestFunctionDisableDeclaration(t *testing.T) { fn, err := NewFunction("in", DisableDeclaration(true), Overload("in_list", - []*Type{NewListType(NewTypeParamType("K")), NewTypeParamType("K")}, - BoolType, + []*types.Type{types.NewListType(types.NewTypeParamType("K")), types.NewTypeParamType("K")}, + types.BoolType, ), ) if err != nil { @@ -657,8 +681,8 @@ func TestFunctionEnableDeclaration(t *testing.T) { fn, err := NewFunction("in", DisableDeclaration(false), Overload("in_list", - []*Type{NewListType(NewTypeParamType("K")), NewTypeParamType("K")}, - BoolType), + []*types.Type{types.NewListType(types.NewTypeParamType("K")), types.NewTypeParamType("K")}, + types.BoolType), ) if err != nil { t.Fatalf("NewFunction() failed: %v", err) @@ -669,8 +693,8 @@ func TestFunctionEnableDeclaration(t *testing.T) { fn2, err := NewFunction("in", DisableDeclaration(true), Overload("in_list", - []*Type{NewListType(NewTypeParamType("K")), NewTypeParamType("K")}, - BoolType), + []*types.Type{types.NewListType(types.NewTypeParamType("K")), types.NewTypeParamType("K")}, + types.BoolType), ) if err != nil { t.Fatalf("NewFunction() failed: %v", err) @@ -704,7 +728,8 @@ func TestFunctionDeclToExprDecl(t *testing.T) { }{ { fn: testFunction(t, "equals", - Overload("equals_value_value", []*Type{NewTypeParamType("T"), NewTypeParamType("T")}, BoolType)), + Overload("equals_value_value", + []*types.Type{types.NewTypeParamType("T"), types.NewTypeParamType("T")}, types.BoolType)), exDecl: &exprpb.Decl{ Name: "equals", DeclKind: &exprpb.Decl_Function{ @@ -726,7 +751,8 @@ func TestFunctionDeclToExprDecl(t *testing.T) { }, { fn: testFunction(t, "equals", - MemberOverload("value_equals_value", []*Type{NewTypeParamType("T"), NewTypeParamType("T")}, BoolType)), + MemberOverload("value_equals_value", + []*types.Type{types.NewTypeParamType("T"), types.NewTypeParamType("T")}, types.BoolType)), exDecl: &exprpb.Decl{ Name: "equals", DeclKind: &exprpb.Decl_Function{ @@ -749,7 +775,8 @@ func TestFunctionDeclToExprDecl(t *testing.T) { }, { fn: testFunction(t, "equals", - Overload("equals_int_uint", []*Type{IntType, UintType}, BoolType)), + Overload("equals_int_uint", + []*types.Type{types.IntType, types.UintType}, types.BoolType)), exDecl: &exprpb.Decl{ Name: "equals", DeclKind: &exprpb.Decl_Function{ @@ -770,7 +797,8 @@ func TestFunctionDeclToExprDecl(t *testing.T) { }, { fn: testFunction(t, "equals", - MemberOverload("int_equals_uint", []*Type{IntType, UintType}, BoolType)), + MemberOverload("int_equals_uint", + []*types.Type{types.IntType, types.UintType}, types.BoolType)), exDecl: &exprpb.Decl{ Name: "equals", DeclKind: &exprpb.Decl_Function{ @@ -792,10 +820,10 @@ func TestFunctionDeclToExprDecl(t *testing.T) { }, { fn: testFunction(t, "equals", - MemberOverload("list_optional_value_equals_list_optional_value", []*Type{ - NewListType(NewOptionalType(NewTypeParamType("T"))), - NewListType(NewOptionalType(NewTypeParamType("T"))), - }, BoolType)), + MemberOverload("list_optional_value_equals_list_optional_value", []*types.Type{ + types.NewListType(types.NewOptionalType(types.NewTypeParamType("T"))), + types.NewListType(types.NewOptionalType(types.NewTypeParamType("T"))), + }, types.BoolType)), exDecl: &exprpb.Decl{ Name: "equals", DeclKind: &exprpb.Decl_Function{ @@ -818,8 +846,10 @@ func TestFunctionDeclToExprDecl(t *testing.T) { }, { fn: testFunction(t, "equals", - MemberOverload("int_equals_uint", []*Type{IntType, UintType}, BoolType), - MemberOverload("uint_equals_int", []*Type{UintType, IntType}, BoolType)), + MemberOverload("int_equals_uint", + []*types.Type{types.IntType, types.UintType}, types.BoolType), + MemberOverload("uint_equals_int", + []*types.Type{types.UintType, types.IntType}, types.BoolType)), exDecl: &exprpb.Decl{ Name: "equals", DeclKind: &exprpb.Decl_Function{ @@ -852,12 +882,12 @@ func TestFunctionDeclToExprDecl(t *testing.T) { { fn: testMerge(t, testFunction(t, "equals", - Overload("int_equals_uint", []*Type{IntType, UintType}, BoolType), - Overload("uint_equals_int", []*Type{UintType, IntType}, BoolType)), + Overload("int_equals_uint", []*types.Type{types.IntType, types.UintType}, types.BoolType), + Overload("uint_equals_int", []*types.Type{types.UintType, types.IntType}, types.BoolType)), testFunction(t, "equals", - Overload("int_equals_int", []*Type{IntType, IntType}, BoolType), - Overload("int_equals_uint", []*Type{IntType, UintType}, BoolType), - Overload("uint_equals_uint", []*Type{UintType, UintType}, BoolType))), + Overload("int_equals_int", []*types.Type{types.IntType, types.IntType}, types.BoolType), + Overload("int_equals_uint", []*types.Type{types.IntType, types.UintType}, types.BoolType), + Overload("uint_equals_uint", []*types.Type{types.UintType, types.UintType}, types.BoolType))), exDecl: &exprpb.Decl{ Name: "equals", DeclKind: &exprpb.Decl_Function{ @@ -914,13 +944,13 @@ func TestFunctionDeclToExprDecl(t *testing.T) { func TestFunctionDeclToExprDeclInvalid(t *testing.T) { fn1 := testFunction(t, "bad_equals", - MemberOverload("bad_equals_param", []*Type{{}, UintType}, BoolType)) + MemberOverload("bad_equals_param", []*types.Type{{}, types.UintType}, types.BoolType)) ex1, err := FunctionDeclToExprDecl(fn1) if err == nil { t.Errorf("FunctionDeclToExprDecl(bad_equals) succeeded: %v, wanted error", ex1) } fn2 := testFunction(t, "bad_equals", - Overload("bad_equals_out", []*Type{IntType, UintType}, &Type{})) + Overload("bad_equals_out", []*types.Type{types.IntType, types.UintType}, &types.Type{})) ex2, err := FunctionDeclToExprDecl(fn2) if err == nil { t.Errorf("FunctionDeclToExprDecl(bad_equals) succeeded: %v, wanted error", ex2) @@ -928,21 +958,50 @@ func TestFunctionDeclToExprDeclInvalid(t *testing.T) { } func TestNewVariable(t *testing.T) { - a := NewVariable("a", BoolType) + a := NewVariable("a", types.BoolType) if !a.DeclarationEquals(a) { t.Error("NewVariable(a, bool) does not equal itself") } - if !a.DeclarationEquals(NewVariable("a", BoolType)) { + if !a.DeclarationEquals(NewVariable("a", types.BoolType)) { t.Error("NewVariable(a, bool) does not equal itself") } - a1 := NewVariable("a", IntType) + a1 := NewVariable("a", types.IntType) if a.DeclarationEquals(a1) { t.Error("NewVariable(a, int).DeclarationEquals(NewVariable(a, bool))") } } +func TestTypeVariable(t *testing.T) { + tests := []struct { + t *types.Type + v *VariableDecl + }{ + { + t: types.AnyType, + v: NewVariable("google.protobuf.Any", types.NewTypeTypeWithParam(types.AnyType)), + }, + { + t: types.DynType, + v: NewVariable("dyn", types.NewTypeTypeWithParam(types.DynType)), + }, + { + t: types.NewObjectType("google.protobuf.Int32Value"), + v: NewVariable("int", types.NewTypeTypeWithParam(types.NewNullableType(types.IntType))), + }, + { + t: types.NewObjectType("google.protobuf.Int32Value"), + v: NewVariable("int", types.NewTypeTypeWithParam(types.NewNullableType(types.IntType))), + }, + } + for _, tst := range tests { + if !TypeVariable(tst.t).DeclarationEquals(tst.v) { + t.Errorf("got not equal %v.Equals(%v)", TypeVariable(tst.t), tst.v) + } + } +} + func TestVariableDeclToExprDecl(t *testing.T) { - a, err := VariableDeclToExprDecl(NewVariable("a", BoolType)) + a, err := VariableDeclToExprDecl(NewVariable("a", types.BoolType)) if err != nil { t.Fatalf("VariableDeclToExprDecl() failed: %v", err) } @@ -953,7 +1012,7 @@ func TestVariableDeclToExprDecl(t *testing.T) { } func TestVariableDeclToExprDeclInvalid(t *testing.T) { - out, err := VariableDeclToExprDecl(NewVariable("bad", &Type{})) + out, err := VariableDeclToExprDecl(NewVariable("bad", &types.Type{})) if err == nil { t.Fatalf("VariableDeclToExprDecl() succeeded: %v, wanted error", out) } diff --git a/common/stdlib/standard.go b/common/stdlib/standard.go index 5a4dc87f..0dd4dffa 100644 --- a/common/stdlib/standard.go +++ b/common/stdlib/standard.go @@ -35,24 +35,24 @@ var ( ) func init() { - paramA := decls.NewTypeParamType("A") - paramB := decls.NewTypeParamType("B") - listOfA := decls.NewListType(paramA) - mapOfAB := decls.NewMapType(paramA, paramB) + paramA := types.NewTypeParamType("A") + paramB := types.NewTypeParamType("B") + listOfA := types.NewListType(paramA) + mapOfAB := types.NewMapType(paramA, paramB) stdTypes = []*decls.VariableDecl{ - decls.TypeVariable(decls.BoolType), - decls.TypeVariable(decls.BytesType), - decls.TypeVariable(decls.DoubleType), - decls.TypeVariable(decls.DurationType), - decls.TypeVariable(decls.IntType), + decls.TypeVariable(types.BoolType), + decls.TypeVariable(types.BytesType), + decls.TypeVariable(types.DoubleType), + decls.TypeVariable(types.DurationType), + decls.TypeVariable(types.IntType), decls.TypeVariable(listOfA), decls.TypeVariable(mapOfAB), - decls.TypeVariable(decls.NullType), - decls.TypeVariable(decls.StringType), - decls.TypeVariable(decls.TimestampType), - decls.TypeVariable(decls.TypeType), - decls.TypeVariable(decls.UintType), + decls.TypeVariable(types.NullType), + decls.TypeVariable(types.StringType), + decls.TypeVariable(types.TimestampType), + decls.TypeVariable(types.TypeType), + decls.TypeVariable(types.UintType), } stdTypeDecls = make([]*exprpb.Decl, 0, len(stdTypes)) @@ -68,19 +68,19 @@ func init() { // Logical operators. Special-cased within the interpreter. // Note, the singleton binding prevents extensions from overriding the operator behavior. function(operators.Conditional, - decls.Overload(overloads.Conditional, argTypes(decls.BoolType, paramA, paramA), paramA, + decls.Overload(overloads.Conditional, argTypes(types.BoolType, paramA, paramA), paramA, decls.OverloadIsNonStrict()), decls.SingletonFunctionBinding(noFunctionOverrides)), function(operators.LogicalAnd, - decls.Overload(overloads.LogicalAnd, argTypes(decls.BoolType, decls.BoolType), decls.BoolType, + decls.Overload(overloads.LogicalAnd, argTypes(types.BoolType, types.BoolType), types.BoolType, decls.OverloadIsNonStrict()), decls.SingletonBinaryBinding(noBinaryOverrides)), function(operators.LogicalOr, - decls.Overload(overloads.LogicalOr, argTypes(decls.BoolType, decls.BoolType), decls.BoolType, + decls.Overload(overloads.LogicalOr, argTypes(types.BoolType, types.BoolType), types.BoolType, decls.OverloadIsNonStrict()), decls.SingletonBinaryBinding(noBinaryOverrides)), function(operators.LogicalNot, - decls.Overload(overloads.LogicalNot, argTypes(decls.BoolType), decls.BoolType), + decls.Overload(overloads.LogicalNot, argTypes(types.BoolType), types.BoolType), decls.SingletonUnaryBinding(func(val ref.Val) ref.Val { b, ok := val.(types.Bool) if !ok { @@ -91,78 +91,78 @@ func init() { // Comprehension short-circuiting related function function(operators.NotStrictlyFalse, - decls.Overload(overloads.NotStrictlyFalse, argTypes(decls.BoolType), decls.BoolType, + decls.Overload(overloads.NotStrictlyFalse, argTypes(types.BoolType), types.BoolType, decls.OverloadIsNonStrict(), decls.UnaryBinding(notStrictlyFalse))), // Deprecated: __not_strictly_false__ function(operators.OldNotStrictlyFalse, decls.DisableDeclaration(true), // safe deprecation - decls.Overload(operators.OldNotStrictlyFalse, argTypes(decls.BoolType), decls.BoolType, + decls.Overload(operators.OldNotStrictlyFalse, argTypes(types.BoolType), types.BoolType, decls.OverloadIsNonStrict(), decls.UnaryBinding(notStrictlyFalse))), // Equality / inequality. Special-cased in the interpreter function(operators.Equals, - decls.Overload(overloads.Equals, argTypes(paramA, paramA), decls.BoolType), + decls.Overload(overloads.Equals, argTypes(paramA, paramA), types.BoolType), decls.SingletonBinaryBinding(noBinaryOverrides)), function(operators.NotEquals, - decls.Overload(overloads.NotEquals, argTypes(paramA, paramA), decls.BoolType), + decls.Overload(overloads.NotEquals, argTypes(paramA, paramA), types.BoolType), decls.SingletonBinaryBinding(noBinaryOverrides)), // Mathematical operators function(operators.Add, decls.Overload(overloads.AddBytes, - argTypes(decls.BytesType, decls.BytesType), decls.BytesType), + argTypes(types.BytesType, types.BytesType), types.BytesType), decls.Overload(overloads.AddDouble, - argTypes(decls.DoubleType, decls.DoubleType), decls.DoubleType), + argTypes(types.DoubleType, types.DoubleType), types.DoubleType), decls.Overload(overloads.AddDurationDuration, - argTypes(decls.DurationType, decls.DurationType), decls.DurationType), + argTypes(types.DurationType, types.DurationType), types.DurationType), decls.Overload(overloads.AddDurationTimestamp, - argTypes(decls.DurationType, decls.TimestampType), decls.TimestampType), + argTypes(types.DurationType, types.TimestampType), types.TimestampType), decls.Overload(overloads.AddTimestampDuration, - argTypes(decls.TimestampType, decls.DurationType), decls.TimestampType), + argTypes(types.TimestampType, types.DurationType), types.TimestampType), decls.Overload(overloads.AddInt64, - argTypes(decls.IntType, decls.IntType), decls.IntType), + argTypes(types.IntType, types.IntType), types.IntType), decls.Overload(overloads.AddList, argTypes(listOfA, listOfA), listOfA), decls.Overload(overloads.AddString, - argTypes(decls.StringType, decls.StringType), decls.StringType), + argTypes(types.StringType, types.StringType), types.StringType), decls.Overload(overloads.AddUint64, - argTypes(decls.UintType, decls.UintType), decls.UintType), + argTypes(types.UintType, types.UintType), types.UintType), decls.SingletonBinaryBinding(func(lhs, rhs ref.Val) ref.Val { return lhs.(traits.Adder).Add(rhs) }, traits.AdderType)), function(operators.Divide, decls.Overload(overloads.DivideDouble, - argTypes(decls.DoubleType, decls.DoubleType), decls.DoubleType), + argTypes(types.DoubleType, types.DoubleType), types.DoubleType), decls.Overload(overloads.DivideInt64, - argTypes(decls.IntType, decls.IntType), decls.IntType), + argTypes(types.IntType, types.IntType), types.IntType), decls.Overload(overloads.DivideUint64, - argTypes(decls.UintType, decls.UintType), decls.UintType), + argTypes(types.UintType, types.UintType), types.UintType), decls.SingletonBinaryBinding(func(lhs, rhs ref.Val) ref.Val { return lhs.(traits.Divider).Divide(rhs) }, traits.DividerType)), function(operators.Modulo, decls.Overload(overloads.ModuloInt64, - argTypes(decls.IntType, decls.IntType), decls.IntType), + argTypes(types.IntType, types.IntType), types.IntType), decls.Overload(overloads.ModuloUint64, - argTypes(decls.UintType, decls.UintType), decls.UintType), + argTypes(types.UintType, types.UintType), types.UintType), decls.SingletonBinaryBinding(func(lhs, rhs ref.Val) ref.Val { return lhs.(traits.Modder).Modulo(rhs) }, traits.ModderType)), function(operators.Multiply, decls.Overload(overloads.MultiplyDouble, - argTypes(decls.DoubleType, decls.DoubleType), decls.DoubleType), + argTypes(types.DoubleType, types.DoubleType), types.DoubleType), decls.Overload(overloads.MultiplyInt64, - argTypes(decls.IntType, decls.IntType), decls.IntType), + argTypes(types.IntType, types.IntType), types.IntType), decls.Overload(overloads.MultiplyUint64, - argTypes(decls.UintType, decls.UintType), decls.UintType), + argTypes(types.UintType, types.UintType), types.UintType), decls.SingletonBinaryBinding(func(lhs, rhs ref.Val) ref.Val { return lhs.(traits.Multiplier).Multiply(rhs) }, traits.MultiplierType)), function(operators.Negate, - decls.Overload(overloads.NegateDouble, argTypes(decls.DoubleType), decls.DoubleType), - decls.Overload(overloads.NegateInt64, argTypes(decls.IntType), decls.IntType), + decls.Overload(overloads.NegateDouble, argTypes(types.DoubleType), types.DoubleType), + decls.Overload(overloads.NegateInt64, argTypes(types.IntType), types.IntType), decls.SingletonUnaryBinding(func(val ref.Val) ref.Val { if types.IsBool(val) { return types.MaybeNoSuchOverloadErr(val) @@ -171,17 +171,17 @@ func init() { }, traits.NegatorType)), function(operators.Subtract, decls.Overload(overloads.SubtractDouble, - argTypes(decls.DoubleType, decls.DoubleType), decls.DoubleType), + argTypes(types.DoubleType, types.DoubleType), types.DoubleType), decls.Overload(overloads.SubtractDurationDuration, - argTypes(decls.DurationType, decls.DurationType), decls.DurationType), + argTypes(types.DurationType, types.DurationType), types.DurationType), decls.Overload(overloads.SubtractInt64, - argTypes(decls.IntType, decls.IntType), decls.IntType), + argTypes(types.IntType, types.IntType), types.IntType), decls.Overload(overloads.SubtractTimestampDuration, - argTypes(decls.TimestampType, decls.DurationType), decls.TimestampType), + argTypes(types.TimestampType, types.DurationType), types.TimestampType), decls.Overload(overloads.SubtractTimestampTimestamp, - argTypes(decls.TimestampType, decls.TimestampType), decls.DurationType), + argTypes(types.TimestampType, types.TimestampType), types.DurationType), decls.Overload(overloads.SubtractUint64, - argTypes(decls.UintType, decls.UintType), decls.UintType), + argTypes(types.UintType, types.UintType), types.UintType), decls.SingletonBinaryBinding(func(lhs, rhs ref.Val) ref.Val { return lhs.(traits.Subtractor).Subtract(rhs) }, traits.SubtractorType)), @@ -190,33 +190,33 @@ func init() { function(operators.Less, decls.Overload(overloads.LessBool, - argTypes(decls.BoolType, decls.BoolType), decls.BoolType), + argTypes(types.BoolType, types.BoolType), types.BoolType), decls.Overload(overloads.LessInt64, - argTypes(decls.IntType, decls.IntType), decls.BoolType), + argTypes(types.IntType, types.IntType), types.BoolType), decls.Overload(overloads.LessInt64Double, - argTypes(decls.IntType, decls.DoubleType), decls.BoolType), + argTypes(types.IntType, types.DoubleType), types.BoolType), decls.Overload(overloads.LessInt64Uint64, - argTypes(decls.IntType, decls.UintType), decls.BoolType), + argTypes(types.IntType, types.UintType), types.BoolType), decls.Overload(overloads.LessUint64, - argTypes(decls.UintType, decls.UintType), decls.BoolType), + argTypes(types.UintType, types.UintType), types.BoolType), decls.Overload(overloads.LessUint64Double, - argTypes(decls.UintType, decls.DoubleType), decls.BoolType), + argTypes(types.UintType, types.DoubleType), types.BoolType), decls.Overload(overloads.LessUint64Int64, - argTypes(decls.UintType, decls.IntType), decls.BoolType), + argTypes(types.UintType, types.IntType), types.BoolType), decls.Overload(overloads.LessDouble, - argTypes(decls.DoubleType, decls.DoubleType), decls.BoolType), + argTypes(types.DoubleType, types.DoubleType), types.BoolType), decls.Overload(overloads.LessDoubleInt64, - argTypes(decls.DoubleType, decls.IntType), decls.BoolType), + argTypes(types.DoubleType, types.IntType), types.BoolType), decls.Overload(overloads.LessDoubleUint64, - argTypes(decls.DoubleType, decls.UintType), decls.BoolType), + argTypes(types.DoubleType, types.UintType), types.BoolType), decls.Overload(overloads.LessString, - argTypes(decls.StringType, decls.StringType), decls.BoolType), + argTypes(types.StringType, types.StringType), types.BoolType), decls.Overload(overloads.LessBytes, - argTypes(decls.BytesType, decls.BytesType), decls.BoolType), + argTypes(types.BytesType, types.BytesType), types.BoolType), decls.Overload(overloads.LessTimestamp, - argTypes(decls.TimestampType, decls.TimestampType), decls.BoolType), + argTypes(types.TimestampType, types.TimestampType), types.BoolType), decls.Overload(overloads.LessDuration, - argTypes(decls.DurationType, decls.DurationType), decls.BoolType), + argTypes(types.DurationType, types.DurationType), types.BoolType), decls.SingletonBinaryBinding(func(lhs, rhs ref.Val) ref.Val { cmp := lhs.(traits.Comparer).Compare(rhs) if cmp == types.IntNegOne { @@ -230,33 +230,33 @@ func init() { function(operators.LessEquals, decls.Overload(overloads.LessEqualsBool, - argTypes(decls.BoolType, decls.BoolType), decls.BoolType), + argTypes(types.BoolType, types.BoolType), types.BoolType), decls.Overload(overloads.LessEqualsInt64, - argTypes(decls.IntType, decls.IntType), decls.BoolType), + argTypes(types.IntType, types.IntType), types.BoolType), decls.Overload(overloads.LessEqualsInt64Double, - argTypes(decls.IntType, decls.DoubleType), decls.BoolType), + argTypes(types.IntType, types.DoubleType), types.BoolType), decls.Overload(overloads.LessEqualsInt64Uint64, - argTypes(decls.IntType, decls.UintType), decls.BoolType), + argTypes(types.IntType, types.UintType), types.BoolType), decls.Overload(overloads.LessEqualsUint64, - argTypes(decls.UintType, decls.UintType), decls.BoolType), + argTypes(types.UintType, types.UintType), types.BoolType), decls.Overload(overloads.LessEqualsUint64Double, - argTypes(decls.UintType, decls.DoubleType), decls.BoolType), + argTypes(types.UintType, types.DoubleType), types.BoolType), decls.Overload(overloads.LessEqualsUint64Int64, - argTypes(decls.UintType, decls.IntType), decls.BoolType), + argTypes(types.UintType, types.IntType), types.BoolType), decls.Overload(overloads.LessEqualsDouble, - argTypes(decls.DoubleType, decls.DoubleType), decls.BoolType), + argTypes(types.DoubleType, types.DoubleType), types.BoolType), decls.Overload(overloads.LessEqualsDoubleInt64, - argTypes(decls.DoubleType, decls.IntType), decls.BoolType), + argTypes(types.DoubleType, types.IntType), types.BoolType), decls.Overload(overloads.LessEqualsDoubleUint64, - argTypes(decls.DoubleType, decls.UintType), decls.BoolType), + argTypes(types.DoubleType, types.UintType), types.BoolType), decls.Overload(overloads.LessEqualsString, - argTypes(decls.StringType, decls.StringType), decls.BoolType), + argTypes(types.StringType, types.StringType), types.BoolType), decls.Overload(overloads.LessEqualsBytes, - argTypes(decls.BytesType, decls.BytesType), decls.BoolType), + argTypes(types.BytesType, types.BytesType), types.BoolType), decls.Overload(overloads.LessEqualsTimestamp, - argTypes(decls.TimestampType, decls.TimestampType), decls.BoolType), + argTypes(types.TimestampType, types.TimestampType), types.BoolType), decls.Overload(overloads.LessEqualsDuration, - argTypes(decls.DurationType, decls.DurationType), decls.BoolType), + argTypes(types.DurationType, types.DurationType), types.BoolType), decls.SingletonBinaryBinding(func(lhs, rhs ref.Val) ref.Val { cmp := lhs.(traits.Comparer).Compare(rhs) if cmp == types.IntNegOne || cmp == types.IntZero { @@ -270,33 +270,33 @@ func init() { function(operators.Greater, decls.Overload(overloads.GreaterBool, - argTypes(decls.BoolType, decls.BoolType), decls.BoolType), + argTypes(types.BoolType, types.BoolType), types.BoolType), decls.Overload(overloads.GreaterInt64, - argTypes(decls.IntType, decls.IntType), decls.BoolType), + argTypes(types.IntType, types.IntType), types.BoolType), decls.Overload(overloads.GreaterInt64Double, - argTypes(decls.IntType, decls.DoubleType), decls.BoolType), + argTypes(types.IntType, types.DoubleType), types.BoolType), decls.Overload(overloads.GreaterInt64Uint64, - argTypes(decls.IntType, decls.UintType), decls.BoolType), + argTypes(types.IntType, types.UintType), types.BoolType), decls.Overload(overloads.GreaterUint64, - argTypes(decls.UintType, decls.UintType), decls.BoolType), + argTypes(types.UintType, types.UintType), types.BoolType), decls.Overload(overloads.GreaterUint64Double, - argTypes(decls.UintType, decls.DoubleType), decls.BoolType), + argTypes(types.UintType, types.DoubleType), types.BoolType), decls.Overload(overloads.GreaterUint64Int64, - argTypes(decls.UintType, decls.IntType), decls.BoolType), + argTypes(types.UintType, types.IntType), types.BoolType), decls.Overload(overloads.GreaterDouble, - argTypes(decls.DoubleType, decls.DoubleType), decls.BoolType), + argTypes(types.DoubleType, types.DoubleType), types.BoolType), decls.Overload(overloads.GreaterDoubleInt64, - argTypes(decls.DoubleType, decls.IntType), decls.BoolType), + argTypes(types.DoubleType, types.IntType), types.BoolType), decls.Overload(overloads.GreaterDoubleUint64, - argTypes(decls.DoubleType, decls.UintType), decls.BoolType), + argTypes(types.DoubleType, types.UintType), types.BoolType), decls.Overload(overloads.GreaterString, - argTypes(decls.StringType, decls.StringType), decls.BoolType), + argTypes(types.StringType, types.StringType), types.BoolType), decls.Overload(overloads.GreaterBytes, - argTypes(decls.BytesType, decls.BytesType), decls.BoolType), + argTypes(types.BytesType, types.BytesType), types.BoolType), decls.Overload(overloads.GreaterTimestamp, - argTypes(decls.TimestampType, decls.TimestampType), decls.BoolType), + argTypes(types.TimestampType, types.TimestampType), types.BoolType), decls.Overload(overloads.GreaterDuration, - argTypes(decls.DurationType, decls.DurationType), decls.BoolType), + argTypes(types.DurationType, types.DurationType), types.BoolType), decls.SingletonBinaryBinding(func(lhs, rhs ref.Val) ref.Val { cmp := lhs.(traits.Comparer).Compare(rhs) if cmp == types.IntOne { @@ -310,33 +310,33 @@ func init() { function(operators.GreaterEquals, decls.Overload(overloads.GreaterEqualsBool, - argTypes(decls.BoolType, decls.BoolType), decls.BoolType), + argTypes(types.BoolType, types.BoolType), types.BoolType), decls.Overload(overloads.GreaterEqualsInt64, - argTypes(decls.IntType, decls.IntType), decls.BoolType), + argTypes(types.IntType, types.IntType), types.BoolType), decls.Overload(overloads.GreaterEqualsInt64Double, - argTypes(decls.IntType, decls.DoubleType), decls.BoolType), + argTypes(types.IntType, types.DoubleType), types.BoolType), decls.Overload(overloads.GreaterEqualsInt64Uint64, - argTypes(decls.IntType, decls.UintType), decls.BoolType), + argTypes(types.IntType, types.UintType), types.BoolType), decls.Overload(overloads.GreaterEqualsUint64, - argTypes(decls.UintType, decls.UintType), decls.BoolType), + argTypes(types.UintType, types.UintType), types.BoolType), decls.Overload(overloads.GreaterEqualsUint64Double, - argTypes(decls.UintType, decls.DoubleType), decls.BoolType), + argTypes(types.UintType, types.DoubleType), types.BoolType), decls.Overload(overloads.GreaterEqualsUint64Int64, - argTypes(decls.UintType, decls.IntType), decls.BoolType), + argTypes(types.UintType, types.IntType), types.BoolType), decls.Overload(overloads.GreaterEqualsDouble, - argTypes(decls.DoubleType, decls.DoubleType), decls.BoolType), + argTypes(types.DoubleType, types.DoubleType), types.BoolType), decls.Overload(overloads.GreaterEqualsDoubleInt64, - argTypes(decls.DoubleType, decls.IntType), decls.BoolType), + argTypes(types.DoubleType, types.IntType), types.BoolType), decls.Overload(overloads.GreaterEqualsDoubleUint64, - argTypes(decls.DoubleType, decls.UintType), decls.BoolType), + argTypes(types.DoubleType, types.UintType), types.BoolType), decls.Overload(overloads.GreaterEqualsString, - argTypes(decls.StringType, decls.StringType), decls.BoolType), + argTypes(types.StringType, types.StringType), types.BoolType), decls.Overload(overloads.GreaterEqualsBytes, - argTypes(decls.BytesType, decls.BytesType), decls.BoolType), + argTypes(types.BytesType, types.BytesType), types.BoolType), decls.Overload(overloads.GreaterEqualsTimestamp, - argTypes(decls.TimestampType, decls.TimestampType), decls.BoolType), + argTypes(types.TimestampType, types.TimestampType), types.BoolType), decls.Overload(overloads.GreaterEqualsDuration, - argTypes(decls.DurationType, decls.DurationType), decls.BoolType), + argTypes(types.DurationType, types.DurationType), types.BoolType), decls.SingletonBinaryBinding(func(lhs, rhs ref.Val) ref.Val { cmp := lhs.(traits.Comparer).Compare(rhs) if cmp == types.IntOne || cmp == types.IntZero { @@ -350,7 +350,7 @@ func init() { // Indexing function(operators.Index, - decls.Overload(overloads.IndexList, argTypes(listOfA, decls.IntType), paramA), + decls.Overload(overloads.IndexList, argTypes(listOfA, types.IntType), paramA), decls.Overload(overloads.IndexMap, argTypes(mapOfAB, paramA), paramB), decls.SingletonBinaryBinding(func(lhs, rhs ref.Val) ref.Val { return lhs.(traits.Indexer).Get(rhs) @@ -358,151 +358,151 @@ func init() { // Collections operators function(operators.In, - decls.Overload(overloads.InList, argTypes(paramA, listOfA), decls.BoolType), - decls.Overload(overloads.InMap, argTypes(paramA, mapOfAB), decls.BoolType), + decls.Overload(overloads.InList, argTypes(paramA, listOfA), types.BoolType), + decls.Overload(overloads.InMap, argTypes(paramA, mapOfAB), types.BoolType), decls.SingletonBinaryBinding(inAggregate)), function(operators.OldIn, decls.DisableDeclaration(true), // safe deprecation - decls.Overload(overloads.InList, argTypes(paramA, listOfA), decls.BoolType), - decls.Overload(overloads.InMap, argTypes(paramA, mapOfAB), decls.BoolType), + decls.Overload(overloads.InList, argTypes(paramA, listOfA), types.BoolType), + decls.Overload(overloads.InMap, argTypes(paramA, mapOfAB), types.BoolType), decls.SingletonBinaryBinding(inAggregate)), function(overloads.DeprecatedIn, decls.DisableDeclaration(true), // safe deprecation - decls.Overload(overloads.InList, argTypes(paramA, listOfA), decls.BoolType), - decls.Overload(overloads.InMap, argTypes(paramA, mapOfAB), decls.BoolType), + decls.Overload(overloads.InList, argTypes(paramA, listOfA), types.BoolType), + decls.Overload(overloads.InMap, argTypes(paramA, mapOfAB), types.BoolType), decls.SingletonBinaryBinding(inAggregate)), function(overloads.Size, - decls.Overload(overloads.SizeBytes, argTypes(decls.BytesType), decls.IntType), - decls.MemberOverload(overloads.SizeBytesInst, argTypes(decls.BytesType), decls.IntType), - decls.Overload(overloads.SizeList, argTypes(listOfA), decls.IntType), - decls.MemberOverload(overloads.SizeListInst, argTypes(listOfA), decls.IntType), - decls.Overload(overloads.SizeMap, argTypes(mapOfAB), decls.IntType), - decls.MemberOverload(overloads.SizeMapInst, argTypes(mapOfAB), decls.IntType), - decls.Overload(overloads.SizeString, argTypes(decls.StringType), decls.IntType), - decls.MemberOverload(overloads.SizeStringInst, argTypes(decls.StringType), decls.IntType), + decls.Overload(overloads.SizeBytes, argTypes(types.BytesType), types.IntType), + decls.MemberOverload(overloads.SizeBytesInst, argTypes(types.BytesType), types.IntType), + decls.Overload(overloads.SizeList, argTypes(listOfA), types.IntType), + decls.MemberOverload(overloads.SizeListInst, argTypes(listOfA), types.IntType), + decls.Overload(overloads.SizeMap, argTypes(mapOfAB), types.IntType), + decls.MemberOverload(overloads.SizeMapInst, argTypes(mapOfAB), types.IntType), + decls.Overload(overloads.SizeString, argTypes(types.StringType), types.IntType), + decls.MemberOverload(overloads.SizeStringInst, argTypes(types.StringType), types.IntType), decls.SingletonUnaryBinding(func(val ref.Val) ref.Val { return val.(traits.Sizer).Size() }, traits.SizerType)), // Type conversions function(overloads.TypeConvertType, - decls.Overload(overloads.TypeConvertType, argTypes(paramA), decls.NewTypeTypeWithParam(paramA)), + decls.Overload(overloads.TypeConvertType, argTypes(paramA), types.NewTypeTypeWithParam(paramA)), decls.SingletonUnaryBinding(convertToType(types.TypeType))), // Bool conversions function(overloads.TypeConvertBool, - decls.Overload(overloads.BoolToBool, argTypes(decls.BoolType), decls.BoolType, + decls.Overload(overloads.BoolToBool, argTypes(types.BoolType), types.BoolType, decls.UnaryBinding(identity)), - decls.Overload(overloads.StringToBool, argTypes(decls.StringType), decls.BoolType, + decls.Overload(overloads.StringToBool, argTypes(types.StringType), types.BoolType, decls.UnaryBinding(convertToType(types.BoolType)))), // Bytes conversions function(overloads.TypeConvertBytes, - decls.Overload(overloads.BytesToBytes, argTypes(decls.BytesType), decls.BytesType, + decls.Overload(overloads.BytesToBytes, argTypes(types.BytesType), types.BytesType, decls.UnaryBinding(identity)), - decls.Overload(overloads.StringToBytes, argTypes(decls.StringType), decls.BytesType, + decls.Overload(overloads.StringToBytes, argTypes(types.StringType), types.BytesType, decls.UnaryBinding(convertToType(types.BytesType)))), // Double conversions function(overloads.TypeConvertDouble, - decls.Overload(overloads.DoubleToDouble, argTypes(decls.DoubleType), decls.DoubleType, + decls.Overload(overloads.DoubleToDouble, argTypes(types.DoubleType), types.DoubleType, decls.UnaryBinding(identity)), - decls.Overload(overloads.IntToDouble, argTypes(decls.IntType), decls.DoubleType, + decls.Overload(overloads.IntToDouble, argTypes(types.IntType), types.DoubleType, decls.UnaryBinding(convertToType(types.DoubleType))), - decls.Overload(overloads.StringToDouble, argTypes(decls.StringType), decls.DoubleType, + decls.Overload(overloads.StringToDouble, argTypes(types.StringType), types.DoubleType, decls.UnaryBinding(convertToType(types.DoubleType))), - decls.Overload(overloads.UintToDouble, argTypes(decls.UintType), decls.DoubleType, + decls.Overload(overloads.UintToDouble, argTypes(types.UintType), types.DoubleType, decls.UnaryBinding(convertToType(types.DoubleType)))), // Duration conversions function(overloads.TypeConvertDuration, - decls.Overload(overloads.DurationToDuration, argTypes(decls.DurationType), decls.DurationType, + decls.Overload(overloads.DurationToDuration, argTypes(types.DurationType), types.DurationType, decls.UnaryBinding(identity)), - decls.Overload(overloads.IntToDuration, argTypes(decls.IntType), decls.DurationType, + decls.Overload(overloads.IntToDuration, argTypes(types.IntType), types.DurationType, decls.UnaryBinding(convertToType(types.DurationType))), - decls.Overload(overloads.StringToDuration, argTypes(decls.StringType), decls.DurationType, + decls.Overload(overloads.StringToDuration, argTypes(types.StringType), types.DurationType, decls.UnaryBinding(convertToType(types.DurationType)))), // Dyn conversions function(overloads.TypeConvertDyn, - decls.Overload(overloads.ToDyn, argTypes(paramA), decls.DynType), + decls.Overload(overloads.ToDyn, argTypes(paramA), types.DynType), decls.SingletonUnaryBinding(identity)), // Int conversions function(overloads.TypeConvertInt, - decls.Overload(overloads.IntToInt, argTypes(decls.IntType), decls.IntType, + decls.Overload(overloads.IntToInt, argTypes(types.IntType), types.IntType, decls.UnaryBinding(identity)), - decls.Overload(overloads.DoubleToInt, argTypes(decls.DoubleType), decls.IntType, + decls.Overload(overloads.DoubleToInt, argTypes(types.DoubleType), types.IntType, decls.UnaryBinding(convertToType(types.IntType))), - decls.Overload(overloads.DurationToInt, argTypes(decls.DurationType), decls.IntType, + decls.Overload(overloads.DurationToInt, argTypes(types.DurationType), types.IntType, decls.UnaryBinding(convertToType(types.IntType))), - decls.Overload(overloads.StringToInt, argTypes(decls.StringType), decls.IntType, + decls.Overload(overloads.StringToInt, argTypes(types.StringType), types.IntType, decls.UnaryBinding(convertToType(types.IntType))), - decls.Overload(overloads.TimestampToInt, argTypes(decls.TimestampType), decls.IntType, + decls.Overload(overloads.TimestampToInt, argTypes(types.TimestampType), types.IntType, decls.UnaryBinding(convertToType(types.IntType))), - decls.Overload(overloads.UintToInt, argTypes(decls.UintType), decls.IntType, + decls.Overload(overloads.UintToInt, argTypes(types.UintType), types.IntType, decls.UnaryBinding(convertToType(types.IntType))), ), // String conversions function(overloads.TypeConvertString, - decls.Overload(overloads.StringToString, argTypes(decls.StringType), decls.StringType, + decls.Overload(overloads.StringToString, argTypes(types.StringType), types.StringType, decls.UnaryBinding(identity)), - decls.Overload(overloads.BoolToString, argTypes(decls.BoolType), decls.StringType, + decls.Overload(overloads.BoolToString, argTypes(types.BoolType), types.StringType, decls.UnaryBinding(convertToType(types.StringType))), - decls.Overload(overloads.BytesToString, argTypes(decls.BytesType), decls.StringType, + decls.Overload(overloads.BytesToString, argTypes(types.BytesType), types.StringType, decls.UnaryBinding(convertToType(types.StringType))), - decls.Overload(overloads.DoubleToString, argTypes(decls.DoubleType), decls.StringType, + decls.Overload(overloads.DoubleToString, argTypes(types.DoubleType), types.StringType, decls.UnaryBinding(convertToType(types.StringType))), - decls.Overload(overloads.DurationToString, argTypes(decls.DurationType), decls.StringType, + decls.Overload(overloads.DurationToString, argTypes(types.DurationType), types.StringType, decls.UnaryBinding(convertToType(types.StringType))), - decls.Overload(overloads.IntToString, argTypes(decls.IntType), decls.StringType, + decls.Overload(overloads.IntToString, argTypes(types.IntType), types.StringType, decls.UnaryBinding(convertToType(types.StringType))), - decls.Overload(overloads.TimestampToString, argTypes(decls.TimestampType), decls.StringType, + decls.Overload(overloads.TimestampToString, argTypes(types.TimestampType), types.StringType, decls.UnaryBinding(convertToType(types.StringType))), - decls.Overload(overloads.UintToString, argTypes(decls.UintType), decls.StringType, + decls.Overload(overloads.UintToString, argTypes(types.UintType), types.StringType, decls.UnaryBinding(convertToType(types.StringType)))), // Timestamp conversions function(overloads.TypeConvertTimestamp, - decls.Overload(overloads.TimestampToTimestamp, argTypes(decls.TimestampType), decls.TimestampType, + decls.Overload(overloads.TimestampToTimestamp, argTypes(types.TimestampType), types.TimestampType, decls.UnaryBinding(identity)), - decls.Overload(overloads.IntToTimestamp, argTypes(decls.IntType), decls.TimestampType, + decls.Overload(overloads.IntToTimestamp, argTypes(types.IntType), types.TimestampType, decls.UnaryBinding(convertToType(types.TimestampType))), - decls.Overload(overloads.StringToTimestamp, argTypes(decls.StringType), decls.TimestampType, + decls.Overload(overloads.StringToTimestamp, argTypes(types.StringType), types.TimestampType, decls.UnaryBinding(convertToType(types.TimestampType)))), // Uint conversions function(overloads.TypeConvertUint, - decls.Overload(overloads.UintToUint, argTypes(decls.UintType), decls.UintType, + decls.Overload(overloads.UintToUint, argTypes(types.UintType), types.UintType, decls.UnaryBinding(identity)), - decls.Overload(overloads.DoubleToUint, argTypes(decls.DoubleType), decls.UintType, + decls.Overload(overloads.DoubleToUint, argTypes(types.DoubleType), types.UintType, decls.UnaryBinding(convertToType(types.UintType))), - decls.Overload(overloads.IntToUint, argTypes(decls.IntType), decls.UintType, + decls.Overload(overloads.IntToUint, argTypes(types.IntType), types.UintType, decls.UnaryBinding(convertToType(types.UintType))), - decls.Overload(overloads.StringToUint, argTypes(decls.StringType), decls.UintType, + decls.Overload(overloads.StringToUint, argTypes(types.StringType), types.UintType, decls.UnaryBinding(convertToType(types.UintType)))), // String functions function(overloads.Contains, decls.MemberOverload(overloads.ContainsString, - argTypes(decls.StringType, decls.StringType), decls.BoolType, + argTypes(types.StringType, types.StringType), types.BoolType, decls.BinaryBinding(types.StringContains)), decls.DisableTypeGuards(true)), function(overloads.EndsWith, decls.MemberOverload(overloads.EndsWithString, - argTypes(decls.StringType, decls.StringType), decls.BoolType, + argTypes(types.StringType, types.StringType), types.BoolType, decls.BinaryBinding(types.StringEndsWith)), decls.DisableTypeGuards(true)), function(overloads.StartsWith, decls.MemberOverload(overloads.StartsWithString, - argTypes(decls.StringType, decls.StringType), decls.BoolType, + argTypes(types.StringType, types.StringType), types.BoolType, decls.BinaryBinding(types.StringStartsWith)), decls.DisableTypeGuards(true)), function(overloads.Matches, - decls.Overload(overloads.Matches, argTypes(decls.StringType, decls.StringType), decls.BoolType), + decls.Overload(overloads.Matches, argTypes(types.StringType, types.StringType), types.BoolType), decls.MemberOverload(overloads.MatchesString, - argTypes(decls.StringType, decls.StringType), decls.BoolType), + argTypes(types.StringType, types.StringType), types.BoolType), decls.SingletonBinaryBinding(func(str, pat ref.Val) ref.Val { return str.(traits.Matcher).Match(pat) }, traits.MatcherType)), @@ -510,71 +510,71 @@ func init() { // Timestamp / duration functions function(overloads.TimeGetFullYear, decls.MemberOverload(overloads.TimestampToYear, - argTypes(decls.TimestampType), decls.IntType), + argTypes(types.TimestampType), types.IntType), decls.MemberOverload(overloads.TimestampToYearWithTz, - argTypes(decls.TimestampType, decls.StringType), decls.IntType)), + argTypes(types.TimestampType, types.StringType), types.IntType)), function(overloads.TimeGetMonth, decls.MemberOverload(overloads.TimestampToMonth, - argTypes(decls.TimestampType), decls.IntType), + argTypes(types.TimestampType), types.IntType), decls.MemberOverload(overloads.TimestampToMonthWithTz, - argTypes(decls.TimestampType, decls.StringType), decls.IntType)), + argTypes(types.TimestampType, types.StringType), types.IntType)), function(overloads.TimeGetDayOfYear, decls.MemberOverload(overloads.TimestampToDayOfYear, - argTypes(decls.TimestampType), decls.IntType), + argTypes(types.TimestampType), types.IntType), decls.MemberOverload(overloads.TimestampToDayOfYearWithTz, - argTypes(decls.TimestampType, decls.StringType), decls.IntType)), + argTypes(types.TimestampType, types.StringType), types.IntType)), function(overloads.TimeGetDayOfMonth, decls.MemberOverload(overloads.TimestampToDayOfMonthZeroBased, - argTypes(decls.TimestampType), decls.IntType), + argTypes(types.TimestampType), types.IntType), decls.MemberOverload(overloads.TimestampToDayOfMonthZeroBasedWithTz, - argTypes(decls.TimestampType, decls.StringType), decls.IntType)), + argTypes(types.TimestampType, types.StringType), types.IntType)), function(overloads.TimeGetDate, decls.MemberOverload(overloads.TimestampToDayOfMonthOneBased, - argTypes(decls.TimestampType), decls.IntType), + argTypes(types.TimestampType), types.IntType), decls.MemberOverload(overloads.TimestampToDayOfMonthOneBasedWithTz, - argTypes(decls.TimestampType, decls.StringType), decls.IntType)), + argTypes(types.TimestampType, types.StringType), types.IntType)), function(overloads.TimeGetDayOfWeek, decls.MemberOverload(overloads.TimestampToDayOfWeek, - argTypes(decls.TimestampType), decls.IntType), + argTypes(types.TimestampType), types.IntType), decls.MemberOverload(overloads.TimestampToDayOfWeekWithTz, - argTypes(decls.TimestampType, decls.StringType), decls.IntType)), + argTypes(types.TimestampType, types.StringType), types.IntType)), function(overloads.TimeGetHours, decls.MemberOverload(overloads.TimestampToHours, - argTypes(decls.TimestampType), decls.IntType), + argTypes(types.TimestampType), types.IntType), decls.MemberOverload(overloads.TimestampToHoursWithTz, - argTypes(decls.TimestampType, decls.StringType), decls.IntType), + argTypes(types.TimestampType, types.StringType), types.IntType), decls.MemberOverload(overloads.DurationToHours, - argTypes(decls.DurationType), decls.IntType)), + argTypes(types.DurationType), types.IntType)), function(overloads.TimeGetMinutes, decls.MemberOverload(overloads.TimestampToMinutes, - argTypes(decls.TimestampType), decls.IntType), + argTypes(types.TimestampType), types.IntType), decls.MemberOverload(overloads.TimestampToMinutesWithTz, - argTypes(decls.TimestampType, decls.StringType), decls.IntType), + argTypes(types.TimestampType, types.StringType), types.IntType), decls.MemberOverload(overloads.DurationToMinutes, - argTypes(decls.DurationType), decls.IntType)), + argTypes(types.DurationType), types.IntType)), function(overloads.TimeGetSeconds, decls.MemberOverload(overloads.TimestampToSeconds, - argTypes(decls.TimestampType), decls.IntType), + argTypes(types.TimestampType), types.IntType), decls.MemberOverload(overloads.TimestampToSecondsWithTz, - argTypes(decls.TimestampType, decls.StringType), decls.IntType), + argTypes(types.TimestampType, types.StringType), types.IntType), decls.MemberOverload(overloads.DurationToSeconds, - argTypes(decls.DurationType), decls.IntType)), + argTypes(types.DurationType), types.IntType)), function(overloads.TimeGetMilliseconds, decls.MemberOverload(overloads.TimestampToMilliseconds, - argTypes(decls.TimestampType), decls.IntType), + argTypes(types.TimestampType), types.IntType), decls.MemberOverload(overloads.TimestampToMillisecondsWithTz, - argTypes(decls.TimestampType, decls.StringType), decls.IntType), + argTypes(types.TimestampType, types.StringType), types.IntType), decls.MemberOverload(overloads.DurationToMilliseconds, - argTypes(decls.DurationType), decls.IntType)), + argTypes(types.DurationType), types.IntType)), } stdFnDecls = make([]*exprpb.Decl, 0, len(stdFunctions)) @@ -634,7 +634,7 @@ func function(name string, opts ...decls.FunctionOpt) *decls.FunctionDecl { return fn } -func argTypes(args ...*decls.Type) []*decls.Type { +func argTypes(args ...*types.Type) []*types.Type { return args } diff --git a/common/types/BUILD.bazel b/common/types/BUILD.bazel index 321d82a3..b5e44ffb 100644 --- a/common/types/BUILD.bazel +++ b/common/types/BUILD.bazel @@ -27,13 +27,14 @@ go_library( "provider.go", "string.go", "timestamp.go", - "type.go", + "types.go", "uint.go", "unknown.go", "util.go", ], importpath = "github.com/google/cel-go/common/types", deps = [ + "//checker/decls:go_default_library", "//common/overloads:go_default_library", "//common/types/pb:go_default_library", "//common/types/ref:go_default_library", @@ -70,7 +71,7 @@ go_test( "provider_test.go", "string_test.go", "timestamp_test.go", - "type_test.go", + "types_test.go", "uint_test.go", "unknown_test.go", "util_test.go", diff --git a/common/types/bool.go b/common/types/bool.go index a634ecc2..565734f3 100644 --- a/common/types/bool.go +++ b/common/types/bool.go @@ -20,7 +20,6 @@ import ( "strconv" "github.com/google/cel-go/common/types/ref" - "github.com/google/cel-go/common/types/traits" anypb "google.golang.org/protobuf/types/known/anypb" structpb "google.golang.org/protobuf/types/known/structpb" @@ -31,11 +30,6 @@ import ( type Bool bool var ( - // BoolType singleton. - BoolType = NewTypeValue("bool", - traits.ComparerType, - traits.NegatorType) - // boolWrapperType golang reflected type for protobuf bool wrapper type. boolWrapperType = reflect.TypeOf(&wrapperspb.BoolValue{}) ) diff --git a/common/types/bytes.go b/common/types/bytes.go index bef19075..5838755f 100644 --- a/common/types/bytes.go +++ b/common/types/bytes.go @@ -22,7 +22,6 @@ import ( "unicode/utf8" "github.com/google/cel-go/common/types/ref" - "github.com/google/cel-go/common/types/traits" anypb "google.golang.org/protobuf/types/known/anypb" structpb "google.golang.org/protobuf/types/known/structpb" @@ -34,12 +33,6 @@ import ( type Bytes []byte var ( - // BytesType singleton. - BytesType = NewTypeValue("bytes", - traits.AdderType, - traits.ComparerType, - traits.SizerType) - // byteWrapperType golang reflected type for protobuf bytes wrapper type. byteWrapperType = reflect.TypeOf(&wrapperspb.BytesValue{}) ) diff --git a/common/types/double.go b/common/types/double.go index bda9f31a..027e7897 100644 --- a/common/types/double.go +++ b/common/types/double.go @@ -20,7 +20,6 @@ import ( "reflect" "github.com/google/cel-go/common/types/ref" - "github.com/google/cel-go/common/types/traits" anypb "google.golang.org/protobuf/types/known/anypb" structpb "google.golang.org/protobuf/types/known/structpb" @@ -32,15 +31,6 @@ import ( type Double float64 var ( - // DoubleType singleton. - DoubleType = NewTypeValue("double", - traits.AdderType, - traits.ComparerType, - traits.DividerType, - traits.MultiplierType, - traits.NegatorType, - traits.SubtractorType) - // doubleWrapperType reflected type for protobuf double wrapper type. doubleWrapperType = reflect.TypeOf(&wrapperspb.DoubleValue{}) diff --git a/common/types/duration.go b/common/types/duration.go index 33340737..596e56d6 100644 --- a/common/types/duration.go +++ b/common/types/duration.go @@ -22,7 +22,6 @@ import ( "github.com/google/cel-go/common/overloads" "github.com/google/cel-go/common/types/ref" - "github.com/google/cel-go/common/types/traits" anypb "google.golang.org/protobuf/types/known/anypb" dpb "google.golang.org/protobuf/types/known/durationpb" @@ -41,14 +40,6 @@ func durationOf(d time.Duration) Duration { } var ( - // DurationType singleton. - DurationType = NewTypeValue("google.protobuf.Duration", - traits.AdderType, - traits.ComparerType, - traits.NegatorType, - traits.ReceiverType, - traits.SubtractorType) - durationValueType = reflect.TypeOf(&dpb.Duration{}) durationZeroArgOverloads = map[string]func(ref.Val) ref.Val{ diff --git a/common/types/int.go b/common/types/int.go index f5a9511c..940772ae 100644 --- a/common/types/int.go +++ b/common/types/int.go @@ -22,7 +22,6 @@ import ( "time" "github.com/google/cel-go/common/types/ref" - "github.com/google/cel-go/common/types/traits" anypb "google.golang.org/protobuf/types/known/anypb" structpb "google.golang.org/protobuf/types/known/structpb" @@ -41,16 +40,6 @@ const ( ) var ( - // IntType singleton. - IntType = NewTypeValue("int", - traits.AdderType, - traits.ComparerType, - traits.DividerType, - traits.ModderType, - traits.MultiplierType, - traits.NegatorType, - traits.SubtractorType) - // int32WrapperType reflected type for protobuf int32 wrapper type. int32WrapperType = reflect.TypeOf(&wrapperspb.Int32Value{}) diff --git a/common/types/list.go b/common/types/list.go index de5f2099..f82906fe 100644 --- a/common/types/list.go +++ b/common/types/list.go @@ -29,16 +29,6 @@ import ( structpb "google.golang.org/protobuf/types/known/structpb" ) -var ( - // ListType singleton. - ListType = NewTypeValue("list", - traits.AdderType, - traits.ContainerType, - traits.IndexerType, - traits.IterableType, - traits.SizerType) -) - // 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. diff --git a/common/types/map.go b/common/types/map.go index 213be4ac..611578a3 100644 --- a/common/types/map.go +++ b/common/types/map.go @@ -94,15 +94,6 @@ func NewProtoMap(adapter ref.TypeAdapter, value *pb.Map) traits.Mapper { } } -var ( - // MapType singleton. - MapType = NewTypeValue("map", - traits.ContainerType, - traits.IndexerType, - traits.IterableType, - traits.SizerType) -) - // mapAccessor is a private interface for finding values within a map and iterating over the keys. // This interface implements portions of the API surface area required by the traits.Mapper // interface. diff --git a/common/types/null.go b/common/types/null.go index 38927a11..926ca3dc 100644 --- a/common/types/null.go +++ b/common/types/null.go @@ -30,8 +30,6 @@ import ( type Null structpb.NullValue var ( - // NullType singleton. - NullType = NewTypeValue("null_type") // NullValue singleton. NullValue = Null(structpb.NullValue_NULL_VALUE) diff --git a/common/types/provider.go b/common/types/provider.go index a6b4e6ff..016d38ba 100644 --- a/common/types/provider.go +++ b/common/types/provider.go @@ -233,6 +233,11 @@ func (p *protoTypeRegistry) NativeToValue(value any) ref.Val { func (p *protoTypeRegistry) registerAllTypes(fd *pb.FileDescription) error { for _, typeName := range fd.GetTypeNames() { + // skip well-known type names since they're automatically sanitized + // during NewObjectType() calls. + if _, found := checkedWellKnowns[typeName]; found { + continue + } err := p.RegisterType(NewObjectTypeValue(typeName)) if err != nil { return err diff --git a/common/types/string.go b/common/types/string.go index 3571b458..028e6824 100644 --- a/common/types/string.go +++ b/common/types/string.go @@ -24,7 +24,6 @@ import ( "github.com/google/cel-go/common/overloads" "github.com/google/cel-go/common/types/ref" - "github.com/google/cel-go/common/types/traits" anypb "google.golang.org/protobuf/types/known/anypb" structpb "google.golang.org/protobuf/types/known/structpb" @@ -36,14 +35,6 @@ import ( type String string var ( - // StringType singleton. - StringType = NewTypeValue("string", - traits.AdderType, - traits.ComparerType, - traits.MatcherType, - traits.ReceiverType, - traits.SizerType) - stringOneArgOverloads = map[string]func(ref.Val, ref.Val) ref.Val{ overloads.Contains: StringContains, overloads.EndsWith: StringEndsWith, diff --git a/common/types/timestamp.go b/common/types/timestamp.go index c784f2e5..33acdea8 100644 --- a/common/types/timestamp.go +++ b/common/types/timestamp.go @@ -23,7 +23,6 @@ import ( "github.com/google/cel-go/common/overloads" "github.com/google/cel-go/common/types/ref" - "github.com/google/cel-go/common/types/traits" anypb "google.golang.org/protobuf/types/known/anypb" structpb "google.golang.org/protobuf/types/known/structpb" @@ -53,15 +52,6 @@ const ( maxUnixTime int64 = 253402300799 ) -var ( - // TimestampType singleton. - TimestampType = NewTypeValue("google.protobuf.Timestamp", - traits.AdderType, - traits.ComparerType, - traits.ReceiverType, - traits.SubtractorType) -) - // Add implements traits.Adder.Add. func (t Timestamp) Add(other ref.Val) ref.Val { switch other.Type() { diff --git a/common/types/type.go b/common/types/type.go deleted file mode 100644 index 164a4605..00000000 --- a/common/types/type.go +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2018 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package types - -import ( - "fmt" - "reflect" - - "github.com/google/cel-go/common/types/ref" - "github.com/google/cel-go/common/types/traits" -) - -var ( - // TypeType is the type of a TypeValue. - TypeType = NewTypeValue("type") -) - -// TypeValue is an instance of a Value that describes a value's type. -type TypeValue struct { - name string - traitMask int -} - -// NewTypeValue returns *TypeValue which is both a ref.Type and ref.Val. -func NewTypeValue(name string, traits ...int) *TypeValue { - traitMask := 0 - for _, trait := range traits { - traitMask |= trait - } - return &TypeValue{ - name: name, - traitMask: traitMask} -} - -// NewObjectTypeValue returns a *TypeValue based on the input name, which is -// annotated with the traits relevant to all objects. -func NewObjectTypeValue(name string) *TypeValue { - return NewTypeValue(name, - traits.FieldTesterType, - traits.IndexerType) -} - -// ConvertToNative implements ref.Val.ConvertToNative. -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'") -} - -// ConvertToType implements ref.Val.ConvertToType. -func (t *TypeValue) ConvertToType(typeVal ref.Type) ref.Val { - switch typeVal { - case TypeType: - return TypeType - case StringType: - return String(t.TypeName()) - } - return NewErr("type conversion error from '%s' to '%s'", TypeType, typeVal) -} - -// Equal implements ref.Val.Equal. -func (t *TypeValue) Equal(other ref.Val) ref.Val { - otherType, ok := other.(ref.Type) - return Bool(ok && t.TypeName() == otherType.TypeName()) -} - -// HasTrait indicates whether the type supports the given trait. -// Trait codes are defined in the traits package, e.g. see traits.AdderType. -func (t *TypeValue) HasTrait(trait int) bool { - return trait&t.traitMask == trait -} - -// String implements fmt.Stringer. -func (t *TypeValue) String() string { - return t.name -} - -// Type implements ref.Val.Type. -func (t *TypeValue) Type() ref.Type { - return TypeType -} - -// TypeName gives the type's name as a string. -func (t *TypeValue) TypeName() string { - return t.name -} - -// Value implements ref.Val.Value. -func (t *TypeValue) Value() any { - return t.name -} diff --git a/common/decls/types.go b/common/types/types.go similarity index 98% rename from common/decls/types.go rename to common/types/types.go index f03e0efa..2cf3e7ba 100644 --- a/common/decls/types.go +++ b/common/types/types.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package decls +package types import ( "fmt" @@ -20,14 +20,14 @@ import ( "strings" chkdecls "github.com/google/cel-go/checker/decls" - "github.com/google/cel-go/common/types" "github.com/google/cel-go/common/types/ref" "github.com/google/cel-go/common/types/traits" exprpb "google.golang.org/genproto/googleapis/api/expr/v1alpha1" ) -// Kind indicates a CEL type's kind which is used to differentiate quickly between simple and complex types. +// Kind indicates a CEL type's kind which is used to differentiate quickly between simple +// and complex types. type Kind uint const ( @@ -243,9 +243,9 @@ func (t *Type) ConvertToType(typeVal ref.Type) ref.Val { case TypeType: return TypeType case StringType: - return types.String(t.TypeName()) + return String(t.TypeName()) } - return types.NewErr("type conversion error from '%s' to '%s'", TypeType, typeVal) + return NewErr("type conversion error from '%s' to '%s'", TypeType, typeVal) } // Equal indicates whether two types have the same runtime type name. @@ -254,7 +254,7 @@ func (t *Type) ConvertToType(typeVal ref.Type) ref.Val { // runtime behavior. For a more accurate definition see IsType(). func (t *Type) Equal(other ref.Val) ref.Val { otherType, ok := other.(ref.Type) - return types.Bool(ok && t.TypeName() == otherType.TypeName()) + return Bool(ok && t.TypeName() == otherType.TypeName()) } // HasTrait implements the ref.Type interface method. @@ -377,7 +377,7 @@ func (t *Type) defaultIsAssignableRuntimeType(val ref.Val) bool { case ListKind: elemType := t.Parameters[0] l := val.(traits.Lister) - if l.Size() == types.IntZero { + if l.Size() == IntZero { return true } it := l.Iterator() @@ -387,7 +387,7 @@ func (t *Type) defaultIsAssignableRuntimeType(val ref.Val) bool { keyType := t.Parameters[0] elemType := t.Parameters[1] m := val.(traits.Mapper) - if m.Size() == types.IntZero { + if m.Size() == IntZero { return true } it := m.Iterator() diff --git a/common/decls/types_test.go b/common/types/types_test.go similarity index 76% rename from common/decls/types_test.go rename to common/types/types_test.go index 461c5190..7625ab50 100644 --- a/common/decls/types_test.go +++ b/common/types/types_test.go @@ -12,10 +12,9 @@ // See the License for the specific language governing permissions and // limitations under the License. -package decls +package types import ( - "errors" "reflect" "strings" "testing" @@ -24,9 +23,6 @@ import ( "google.golang.org/protobuf/proto" chkdecls "github.com/google/cel-go/checker/decls" - "github.com/google/cel-go/common/overloads" - "github.com/google/cel-go/common/types" - "github.com/google/cel-go/common/types/ref" "github.com/google/cel-go/common/types/traits" exprpb "google.golang.org/genproto/googleapis/api/expr/v1alpha1" @@ -146,35 +142,6 @@ func TestTypeIsType(t *testing.T) { } } -func TestTypeTypeVariable(t *testing.T) { - tests := []struct { - t *Type - v *VariableDecl - }{ - { - t: AnyType, - v: NewVariable("google.protobuf.Any", NewTypeTypeWithParam(AnyType)), - }, - { - t: DynType, - v: NewVariable("dyn", NewTypeTypeWithParam(DynType)), - }, - { - t: NewObjectType("google.protobuf.Int32Value"), - v: NewVariable("int", NewTypeTypeWithParam(NewNullableType(IntType))), - }, - { - t: NewObjectType("google.protobuf.Int32Value"), - v: NewVariable("int", NewTypeTypeWithParam(NewNullableType(IntType))), - }, - } - for _, tst := range tests { - if !TypeVariable(tst.t).DeclarationEquals(tst.v) { - t.Errorf("got not equal %v.Equals(%v)", TypeVariable(tst.t), tst.v) - } - } -} - func TestTypeIsAssignableType(t *testing.T) { tests := []struct { t1 *Type @@ -244,45 +211,27 @@ func TestTypeIsAssignableType(t *testing.T) { } } -func TestTypeSignatureEquals(t *testing.T) { - paramA := NewTypeParamType("A") - paramB := NewTypeParamType("B") - mapOfAB := NewMapType(paramA, paramB) - fn, err := NewFunction(overloads.Size, - MemberOverload(overloads.SizeMapInst, []*Type{mapOfAB}, IntType), - Overload(overloads.SizeMap, []*Type{mapOfAB}, IntType)) - if err != nil { - t.Fatalf("NewFunction() failed: %v", err) - } - if !fn.Overloads[overloads.SizeMap].SignatureEquals(fn.Overloads[overloads.SizeMap]) { - t.Errorf("SignatureEquals() returned false, wanted true") - } - if fn.Overloads[overloads.SizeMap].SignatureEquals(fn.Overloads[overloads.SizeMapInst]) { - t.Errorf("SignatureEquals() returned false, wanted true") - } -} - func TestTypeIsAssignableRuntimeType(t *testing.T) { - if !NewNullableType(DoubleType).IsAssignableRuntimeType(types.NullValue) { + if !NewNullableType(DoubleType).IsAssignableRuntimeType(NullValue) { t.Error("nullable double cannot be assigned from null") } - if !NewNullableType(DoubleType).IsAssignableRuntimeType(types.Double(0.0)) { + if !NewNullableType(DoubleType).IsAssignableRuntimeType(Double(0.0)) { t.Error("nullable double cannot be assigned from double") } if !NewMapType(StringType, DurationType).IsAssignableRuntimeType( - types.DefaultTypeAdapter.NativeToValue(map[string]time.Duration{})) { + DefaultTypeAdapter.NativeToValue(map[string]time.Duration{})) { t.Error("map(string, duration) not assignable to map at runtime") } if !NewMapType(StringType, DurationType).IsAssignableRuntimeType( - types.DefaultTypeAdapter.NativeToValue(map[string]time.Duration{"one": time.Duration(1)})) { + DefaultTypeAdapter.NativeToValue(map[string]time.Duration{"one": time.Duration(1)})) { t.Error("map(string, duration) not assignable to map at runtime") } if !NewMapType(StringType, DynType).IsAssignableRuntimeType( - types.DefaultTypeAdapter.NativeToValue(map[string]time.Duration{"one": time.Duration(1)})) { + DefaultTypeAdapter.NativeToValue(map[string]time.Duration{"one": time.Duration(1)})) { t.Error("map(string, dyn) not assignable to map at runtime") } if NewMapType(StringType, DynType).IsAssignableRuntimeType( - types.DefaultTypeAdapter.NativeToValue(map[int64]time.Duration{1: time.Duration(1)})) { + DefaultTypeAdapter.NativeToValue(map[int64]time.Duration{1: time.Duration(1)})) { t.Error("map(string, dyn) must not be assignable to map(int, duration) at runtime") } } @@ -709,113 +658,3 @@ func TestTypeConvertToType(t *testing.T) { t.Error("ConvertToNative() did not error") } } - -func TestTypeCommonTypeInterop(t *testing.T) { - tests := []struct { - commonType ref.Type - declType *Type - }{ - { - commonType: types.BoolType, - declType: BoolType, - }, - { - commonType: types.BytesType, - declType: BytesType, - }, - { - commonType: types.DoubleType, - declType: DoubleType, - }, - { - commonType: types.DurationType, - declType: DurationType, - }, - { - commonType: types.ErrType, - declType: ErrorType, - }, - { - commonType: types.IntType, - declType: IntType, - }, - { - commonType: types.ListType, - declType: ListType, - }, - { - commonType: types.MapType, - declType: MapType, - }, - { - commonType: types.NullType, - declType: NullType, - }, - { - commonType: types.StringType, - declType: StringType, - }, - { - commonType: types.TimestampType, - declType: TimestampType, - }, - { - commonType: types.TypeType, - declType: TypeType, - }, - { - commonType: types.UintType, - declType: UintType, - }, - { - commonType: types.UnknownType, - declType: UnknownType, - }, - { - commonType: types.NewObjectTypeValue("dev.cel.Expr"), - declType: NewObjectTypeValue("dev.cel.Expr"), - }, - { - commonType: types.NewTypeValue("vector", traits.AdderType), - declType: NewTypeValue("vector", traits.AdderType), - }, - } - for _, tst := range tests { - tc := tst - t.Run(tc.commonType.TypeName(), func(t *testing.T) { - if tc.commonType.TypeName() != tc.declType.TypeName() { - t.Errorf("type names not equal: got %v, wanted %v", tc.declType.TypeName(), tc.commonType.TypeName()) - } - if !tc.commonType.HasTrait(tc.declType.traitMask) { - t.Errorf("trait masks not equal: mask %v", tc.declType.traitMask) - } - ctVal := tc.commonType.(ref.Val) - if ctVal.Equal(tc.declType) != types.True || - tc.declType.Equal(ctVal) != types.True { - t.Error("types not runtime equal") - } - if ctVal.Type() != types.TypeType { - t.Errorf("type not marked as a type: %v", ctVal.Type()) - } - if tc.declType.Type() != TypeType { - t.Errorf("type not marked as a type: %v", tc.declType.Type()) - } - if ctVal.Value() != tc.declType.Value() { - t.Errorf("type values not equal: got %v, wanted %v", tc.declType.Value(), ctVal.Value()) - } - if ctVal.ConvertToType(types.StringType). - Equal(tc.declType.ConvertToType(StringType)) != types.True { - t.Error("type values did not convert to same string values") - } - if ctVal.ConvertToType(types.TypeType). - Equal(tc.declType.ConvertToType(TypeType)) != types.True { - t.Error("type values did not convert to same type values") - } - if !errors.Is( - ctVal.ConvertToType(types.ErrType).(*types.Err), - tc.declType.ConvertToType(ErrorType).(*types.Err)) { - t.Error("type values did not convert to same error values") - } - }) - } -} diff --git a/common/types/uint.go b/common/types/uint.go index 615c7ec5..3257f9ad 100644 --- a/common/types/uint.go +++ b/common/types/uint.go @@ -21,7 +21,6 @@ import ( "strconv" "github.com/google/cel-go/common/types/ref" - "github.com/google/cel-go/common/types/traits" anypb "google.golang.org/protobuf/types/known/anypb" structpb "google.golang.org/protobuf/types/known/structpb" @@ -32,15 +31,6 @@ import ( type Uint uint64 var ( - // UintType singleton. - UintType = NewTypeValue("uint", - traits.AdderType, - traits.ComparerType, - traits.DividerType, - traits.ModderType, - traits.MultiplierType, - traits.SubtractorType) - uint32WrapperType = reflect.TypeOf(&wrapperspb.UInt32Value{}) uint64WrapperType = reflect.TypeOf(&wrapperspb.UInt64Value{}) diff --git a/common/types/unknown.go b/common/types/unknown.go index a57cd50e..b8f76641 100644 --- a/common/types/unknown.go +++ b/common/types/unknown.go @@ -24,11 +24,6 @@ import ( // current value to become unknown. type Unknown []int64 -var ( - // UnknownType singleton. - UnknownType = NewTypeValue("unknown") -) - // ConvertToNative implements ref.Val.ConvertToNative. func (u Unknown) ConvertToNative(typeDesc reflect.Type) (any, error) { return u.Value(), nil From 69344767187636149bd26f6e60b83a14b28f74d9 Mon Sep 17 00:00:00 2001 From: TristonianJones Date: Fri, 16 Jun 2023 11:23:38 -0700 Subject: [PATCH 2/2] Minor updates to test after merge --- interpreter/attributes_test.go | 44 ++++----- interpreter/interpreter_test.go | 162 ++++++++++++++++---------------- interpreter/prune_test.go | 14 +-- interpreter/runtimecost_test.go | 85 ++++++++--------- 4 files changed, 153 insertions(+), 152 deletions(-) diff --git a/interpreter/attributes_test.go b/interpreter/attributes_test.go index 1d33c5a1..0bea0212 100644 --- a/interpreter/attributes_test.go +++ b/interpreter/attributes_test.go @@ -881,9 +881,9 @@ func TestAttributeStateTracking(t *testing.T) { { expr: `a[1]['two']`, vars: []*decls.VariableDecl{ - decls.NewVariable("a", decls.MapType( - decls.IntType, - decls.MapType(decls.StringType, decls.BoolType))), + decls.NewVariable("a", types.NewMapType( + types.IntType, + types.NewMapType(types.StringType, types.BoolType))), }, in: map[string]any{ "a": map[int64]any{ @@ -903,9 +903,9 @@ func TestAttributeStateTracking(t *testing.T) { { expr: `a[1][2][3]`, vars: []*decls.VariableDecl{ - decls.NewVariable("a", decls.MapType( - decls.IntType, - decls.MapType(decls.DynType, decls.DynType))), + decls.NewVariable("a", types.NewMapType( + types.IntType, + types.NewMapType(types.DynType, types.DynType))), }, in: map[string]any{ "a": map[int64]any{ @@ -931,9 +931,9 @@ func TestAttributeStateTracking(t *testing.T) { { expr: `a[1][2][a[1][1]]`, vars: []*decls.VariableDecl{ - decls.NewVariable("a", decls.MapType( - decls.IntType, - decls.MapType(decls.DynType, decls.DynType))), + decls.NewVariable("a", types.NewMapType( + types.IntType, + types.NewMapType(types.DynType, types.DynType))), }, in: map[string]any{ "a": map[int64]any{ @@ -967,8 +967,8 @@ func TestAttributeStateTracking(t *testing.T) { { expr: `true ? a : b`, vars: []*decls.VariableDecl{ - decls.NewVariable("a", decls.StringType), - decls.NewVariable("b", decls.StringType), + decls.NewVariable("a", types.StringType), + decls.NewVariable("b", types.StringType), }, in: map[string]any{ "a": "hello", @@ -983,8 +983,8 @@ func TestAttributeStateTracking(t *testing.T) { { expr: `(a.size() != 0 ? a : b)[0]`, vars: []*decls.VariableDecl{ - decls.NewVariable("a", decls.ListType(decls.StringType)), - decls.NewVariable("b", decls.ListType(decls.StringType)), + decls.NewVariable("a", types.NewListType(types.StringType)), + decls.NewVariable("b", types.NewListType(types.StringType)), }, in: map[string]any{ "a": []string{"hello", "world"}, @@ -1007,7 +1007,7 @@ func TestAttributeStateTracking(t *testing.T) { { expr: `a.?b.c`, vars: []*decls.VariableDecl{ - decls.NewVariable("a", decls.MapType(decls.StringType, decls.MapType(decls.StringType, decls.StringType))), + decls.NewVariable("a", types.NewMapType(types.StringType, types.NewMapType(types.StringType, types.StringType))), }, in: map[string]any{ "a": map[string]any{"b": map[string]any{"c": "world"}}, @@ -1023,7 +1023,7 @@ func TestAttributeStateTracking(t *testing.T) { { expr: `a.?b.c`, vars: []*decls.VariableDecl{ - decls.NewVariable("a", decls.MapType(decls.StringType, decls.MapType(decls.StringType, decls.StringType))), + decls.NewVariable("a", types.NewMapType(types.StringType, types.NewMapType(types.StringType, types.StringType))), }, in: map[string]any{ "a": map[string]any{"b": map[string]string{"random": "value"}}, @@ -1039,7 +1039,7 @@ func TestAttributeStateTracking(t *testing.T) { { expr: `a.b.c`, vars: []*decls.VariableDecl{ - decls.NewVariable("a", decls.MapType(decls.StringType, decls.MapType(decls.StringType, decls.StringType))), + decls.NewVariable("a", types.NewMapType(types.StringType, types.NewMapType(types.StringType, types.StringType))), }, in: map[string]any{ "a": map[string]any{"b": map[string]any{"c": "world"}}, @@ -1055,8 +1055,8 @@ func TestAttributeStateTracking(t *testing.T) { { expr: `m[has(a.b)]`, vars: []*decls.VariableDecl{ - decls.NewVariable("a", decls.MapType(decls.StringType, decls.StringType)), - decls.NewVariable("m", decls.MapType(decls.BoolType, decls.StringType)), + decls.NewVariable("a", types.NewMapType(types.StringType, types.StringType)), + decls.NewVariable("m", types.NewMapType(types.BoolType, types.StringType)), }, in: map[string]any{ "a": map[string]string{"b": ""}, @@ -1067,8 +1067,8 @@ func TestAttributeStateTracking(t *testing.T) { { expr: `m[?has(a.b)]`, vars: []*decls.VariableDecl{ - decls.NewVariable("a", decls.MapType(decls.StringType, decls.StringType)), - decls.NewVariable("m", decls.MapType(decls.BoolType, decls.StringType)), + decls.NewVariable("a", types.NewMapType(types.StringType, types.StringType)), + decls.NewVariable("m", types.NewMapType(types.BoolType, types.StringType)), }, in: map[string]any{ "a": map[string]string{"b": ""}, @@ -1079,8 +1079,8 @@ func TestAttributeStateTracking(t *testing.T) { { expr: `m[?has(a.b.c)]`, vars: []*decls.VariableDecl{ - decls.NewVariable("a", decls.MapType(decls.StringType, decls.DynType)), - decls.NewVariable("m", decls.MapType(decls.BoolType, decls.StringType)), + decls.NewVariable("a", types.NewMapType(types.StringType, types.DynType)), + decls.NewVariable("m", types.NewMapType(types.BoolType, types.StringType)), }, in: partialActivation( map[string]any{ diff --git a/interpreter/interpreter_test.go b/interpreter/interpreter_test.go index d583afcf..bc1891e1 100644 --- a/interpreter/interpreter_test.go +++ b/interpreter/interpreter_test.go @@ -108,7 +108,7 @@ func testData(t testing.TB) []testCase { unchecked: true, funcs: []*decls.FunctionDecl{ funcDecl(t, "zero", - decls.Overload("zero", []*decls.Type{}, decls.IntType), + decls.Overload("zero", []*types.Type{}, types.IntType), decls.SingletonFunctionBinding(func(args ...ref.Val) ref.Val { return types.IntZero }), @@ -121,7 +121,7 @@ func testData(t testing.TB) []testCase { unchecked: true, funcs: []*decls.FunctionDecl{ funcDecl(t, "neg", - decls.Overload("neg_int", []*decls.Type{decls.IntType}, decls.IntType, + decls.Overload("neg_int", []*types.Type{types.IntType}, types.IntType, decls.OverloadOperandTrait(traits.NegatorType), decls.UnaryBinding(func(arg ref.Val) ref.Val { return arg.(traits.Negater).Negate() @@ -137,7 +137,7 @@ func testData(t testing.TB) []testCase { unchecked: true, funcs: []*decls.FunctionDecl{ funcDecl(t, "concat", - decls.MemberOverload("bytes_concat_bytes", []*decls.Type{decls.BytesType, decls.BytesType}, decls.BytesType, + decls.MemberOverload("bytes_concat_bytes", []*types.Type{types.BytesType, types.BytesType}, types.BytesType, decls.OverloadOperandTrait(traits.AdderType), decls.BinaryBinding(func(lhs, rhs ref.Val) ref.Val { return lhs.(traits.Adder).Add(rhs) @@ -152,8 +152,8 @@ func testData(t testing.TB) []testCase { funcs: []*decls.FunctionDecl{ funcDecl(t, "addall", decls.Overload("addall_four", - []*decls.Type{decls.IntType, decls.IntType, decls.IntType, decls.IntType}, - decls.IntType), + []*types.Type{types.IntType, types.IntType, types.IntType, types.IntType}, + types.IntType), decls.DisableTypeGuards(true), decls.SingletonFunctionBinding(func(args ...ref.Val) ref.Val { val := types.Int(0) @@ -172,7 +172,7 @@ func testData(t testing.TB) []testCase { expr: `base64.encode('hello')`, funcs: []*decls.FunctionDecl{ funcDecl(t, "base64.encode", - decls.Overload("base64_encode_string", []*decls.Type{decls.StringType}, decls.StringType), + decls.Overload("base64_encode_string", []*types.Type{types.StringType}, types.StringType), decls.SingletonUnaryBinding(base64Encode)), }, out: "aGVsbG8=", @@ -183,7 +183,7 @@ func testData(t testing.TB) []testCase { unchecked: true, funcs: []*decls.FunctionDecl{ funcDecl(t, "base64.encode", - decls.Overload("base64_encode_string", []*decls.Type{decls.StringType}, decls.StringType), + decls.Overload("base64_encode_string", []*types.Type{types.StringType}, types.StringType), decls.SingletonUnaryBinding(base64Encode)), }, out: "aGVsbG8=", @@ -194,7 +194,7 @@ func testData(t testing.TB) []testCase { expr: `encode('hello')`, funcs: []*decls.FunctionDecl{ funcDecl(t, "base64.encode", - decls.Overload("base64_encode_string", []*decls.Type{decls.StringType}, decls.StringType), + decls.Overload("base64_encode_string", []*types.Type{types.StringType}, types.StringType), decls.SingletonUnaryBinding(base64Encode)), }, out: "aGVsbG8=", @@ -206,7 +206,7 @@ func testData(t testing.TB) []testCase { unchecked: true, funcs: []*decls.FunctionDecl{ funcDecl(t, "base64.encode", - decls.Overload("base64_encode_string", []*decls.Type{decls.StringType}, decls.StringType), + decls.Overload("base64_encode_string", []*types.Type{types.StringType}, types.StringType), decls.SingletonUnaryBinding(base64Encode)), }, out: "aGVsbG8=", @@ -220,7 +220,7 @@ func testData(t testing.TB) []testCase { (headers.path.startsWith("/admin") && headers.token == "admin" && headers.ip in ["10.0.1.2", "10.0.1.2", "10.0.1.2"])) `, vars: []*decls.VariableDecl{ - decls.NewVariable("headers", decls.MapType(decls.StringType, decls.StringType)), + decls.NewVariable("headers", types.NewMapType(types.StringType, types.StringType)), }, in: map[string]any{ "headers": map[string]any{ @@ -239,9 +239,9 @@ func testData(t testing.TB) []testCase { (headers.path.startsWith("/admin") && headers.token == "admin" && headers.ip in ["10.0.1.2", "10.0.1.2", "10.0.1.2"])) `, vars: []*decls.VariableDecl{ - decls.NewVariable("headers.ip", decls.StringType), - decls.NewVariable("headers.path", decls.StringType), - decls.NewVariable("headers.token", decls.StringType), + decls.NewVariable("headers.ip", types.StringType), + decls.NewVariable("headers.path", types.StringType), + decls.NewVariable("headers.token", types.StringType), }, in: map[string]any{ "headers.ip": "10.0.1.2", @@ -253,9 +253,9 @@ func testData(t testing.TB) []testCase { name: "cond", expr: `a ? b < 1.2 : c == ['hello']`, vars: []*decls.VariableDecl{ - decls.NewVariable("a", decls.BoolType), - decls.NewVariable("b", decls.DoubleType), - decls.NewVariable("c", decls.ListType(decls.StringType)), + decls.NewVariable("a", types.BoolType), + decls.NewVariable("b", types.DoubleType), + decls.NewVariable("c", types.NewListType(types.StringType)), }, in: map[string]any{ "a": true, @@ -268,8 +268,8 @@ func testData(t testing.TB) []testCase { name: "cond_attr_out_of_bounds_error", expr: `m[(x ? 0 : 1)] >= 0`, vars: []*decls.VariableDecl{ - decls.NewVariable("m", decls.ListType(decls.IntType)), - decls.NewVariable("x", decls.BoolType), + decls.NewVariable("m", types.NewListType(types.IntType)), + decls.NewVariable("x", types.BoolType), }, in: map[string]any{ "m": []int{-1}, @@ -281,10 +281,10 @@ func testData(t testing.TB) []testCase { name: "cond_attr_qualify_bad_type_error", expr: `m[(x ? a : b)] >= 0`, vars: []*decls.VariableDecl{ - decls.NewVariable("m", decls.ListType(decls.DynType)), - decls.NewVariable("a", decls.DynType), - decls.NewVariable("b", decls.DynType), - decls.NewVariable("x", decls.BoolType), + decls.NewVariable("m", types.NewListType(types.DynType)), + decls.NewVariable("a", types.DynType), + decls.NewVariable("b", types.DynType), + decls.NewVariable("x", types.BoolType), }, in: map[string]any{ "m": []int{1}, @@ -298,10 +298,10 @@ func testData(t testing.TB) []testCase { name: "cond_attr_qualify_bad_field_error", expr: `m[(x ? a : b).c] >= 0`, vars: []*decls.VariableDecl{ - decls.NewVariable("m", decls.ListType(decls.DynType)), - decls.NewVariable("a", decls.DynType), - decls.NewVariable("b", decls.DynType), - decls.NewVariable("x", decls.BoolType), + decls.NewVariable("m", types.NewListType(types.DynType)), + decls.NewVariable("a", types.DynType), + decls.NewVariable("b", types.DynType), + decls.NewVariable("x", types.BoolType), }, in: map[string]any{ "m": []int{1}, @@ -363,7 +363,7 @@ func testData(t testing.TB) []testCase { name: "in_var_list_int", expr: `6 in [2, 12, x]`, vars: []*decls.VariableDecl{ - decls.NewVariable("x", decls.DynType), + decls.NewVariable("x", types.DynType), }, in: map[string]any{"x": 6}, }, @@ -371,7 +371,7 @@ func testData(t testing.TB) []testCase { name: "in_var_list_uint", expr: `6 in [2, 12, x]`, vars: []*decls.VariableDecl{ - decls.NewVariable("x", decls.DynType), + decls.NewVariable("x", types.DynType), }, in: map[string]any{"x": uint64(6)}, }, @@ -379,7 +379,7 @@ func testData(t testing.TB) []testCase { name: "in_var_list_double", expr: `6 in [2, 12, x]`, vars: []*decls.VariableDecl{ - decls.NewVariable("x", decls.DynType), + decls.NewVariable("x", types.DynType), }, in: map[string]any{"x": 6.0}, }, @@ -387,7 +387,7 @@ func testData(t testing.TB) []testCase { name: "in_var_list_double_double", expr: `dyn(6.0) in [2, 12, x]`, vars: []*decls.VariableDecl{ - decls.NewVariable("x", decls.IntType), + decls.NewVariable("x", types.IntType), }, in: map[string]any{"x": 6}, }, @@ -430,8 +430,8 @@ func testData(t testing.TB) []testCase { expr: `'other-key' in {x: null, y: 42}`, out: types.True, vars: []*decls.VariableDecl{ - decls.NewVariable("x", decls.StringType), - decls.NewVariable("y", decls.IntType), + decls.NewVariable("x", types.StringType), + decls.NewVariable("y", types.IntType), }, in: map[string]any{ "x": "other-key", @@ -443,8 +443,8 @@ func testData(t testing.TB) []testCase { expr: `'other-key' in {1: x, 2u: y}`, out: types.False, vars: []*decls.VariableDecl{ - decls.NewVariable("x", decls.StringType), - decls.NewVariable("y", decls.IntType), + decls.NewVariable("x", types.StringType), + decls.NewVariable("y", types.IntType), }, in: map[string]any{ "x": "other-value", @@ -455,7 +455,7 @@ func testData(t testing.TB) []testCase { name: "index", expr: `m['key'][1] == 42u && m['null'] == null && m[string(0)] == 10`, vars: []*decls.VariableDecl{ - decls.NewVariable("m", decls.MapType(decls.StringType, decls.DynType)), + decls.NewVariable("m", types.NewMapType(types.StringType, types.DynType)), }, in: map[string]any{ "m": map[string]any{ @@ -469,8 +469,8 @@ func testData(t testing.TB) []testCase { name: "index_cross_type_float_uint", expr: `{1: 'hello'}[x] == 'hello' && {2: 'world'}[y] == 'world'`, vars: []*decls.VariableDecl{ - decls.NewVariable("x", decls.DynType), - decls.NewVariable("y", decls.DynType), + decls.NewVariable("x", types.DynType), + decls.NewVariable("y", types.DynType), }, in: map[string]any{ "x": float32(1.0), @@ -481,8 +481,8 @@ func testData(t testing.TB) []testCase { name: "no_index_cross_type_float_uint", expr: `{1: 'hello'}[x] == 'hello' && ['world'][y] == 'world'`, vars: []*decls.VariableDecl{ - decls.NewVariable("x", decls.DynType), - decls.NewVariable("y", decls.DynType), + decls.NewVariable("x", types.DynType), + decls.NewVariable("y", types.DynType), }, in: map[string]any{ "x": float32(2.0), @@ -494,7 +494,7 @@ func testData(t testing.TB) []testCase { name: "index_cross_type_double", expr: `{1: 'hello', 2: 'world'}[x] == 'hello'`, vars: []*decls.VariableDecl{ - decls.NewVariable("x", decls.DynType), + decls.NewVariable("x", types.DynType), }, in: map[string]any{ "x": 1.0, @@ -512,7 +512,7 @@ func testData(t testing.TB) []testCase { name: "index_cross_type_bad_qualifier", expr: `{1: 'hello', 2: 'world'}[x] == 'world'`, vars: []*decls.VariableDecl{ - decls.NewVariable("x", decls.DynType), + decls.NewVariable("x", types.DynType), }, in: map[string]any{ "x": time.Millisecond, @@ -719,8 +719,8 @@ func testData(t testing.TB) []testCase { expr: `code == "111" && ["a", "b"].all(x, x in tags) || code == "222" && ["a", "b"].all(x, x in tags)`, vars: []*decls.VariableDecl{ - decls.NewVariable("code", decls.StringType), - decls.NewVariable("tags", decls.ListType(decls.StringType)), + decls.NewVariable("code", types.StringType), + decls.NewVariable("tags", types.NewListType(types.StringType)), }, in: map[string]any{ "code": "222", @@ -739,7 +739,7 @@ func testData(t testing.TB) []testCase { name: "macro_exists_var", expr: `elems.exists(e, type(e) == uint)`, vars: []*decls.VariableDecl{ - decls.NewVariable("elems", decls.ListType(decls.DynType)), + decls.NewVariable("elems", types.NewListType(types.DynType)), }, in: map[string]any{ "elems": []any{0, 1, 2, 3, 4, uint(5), 6}, @@ -771,7 +771,7 @@ func testData(t testing.TB) []testCase { container: "google.expr.proto2.test", types: []proto.Message{&proto2pb.TestAllTypes{}}, vars: []*decls.VariableDecl{ - decls.NewVariable("pb2", decls.ObjectType("google.expr.proto2.test.TestAllTypes")), + decls.NewVariable("pb2", types.NewObjectType("google.expr.proto2.test.TestAllTypes")), }, in: map[string]any{ "pb2": &proto2pb.TestAllTypes{ @@ -797,7 +797,7 @@ func testData(t testing.TB) []testCase { name: "macro_has_pb3_field", types: []proto.Message{&proto3pb.TestAllTypes{}}, vars: []*decls.VariableDecl{ - decls.NewVariable("pb3", decls.ObjectType("google.expr.proto3.test.TestAllTypes")), + decls.NewVariable("pb3", types.NewObjectType("google.expr.proto3.test.TestAllTypes")), }, container: "google.expr.proto3.test", in: map[string]any{ @@ -830,7 +830,7 @@ func testData(t testing.TB) []testCase { name: "matches_global", expr: `matches(input, 'k.*')`, vars: []*decls.VariableDecl{ - decls.NewVariable("input", decls.StringType), + decls.NewVariable("input", types.StringType), }, in: map[string]any{ "input": "kathmandu", @@ -843,7 +843,7 @@ func testData(t testing.TB) []testCase { && !'bar'.matches('k.*') && 'kilimanjaro'.matches('.*ro')`, vars: []*decls.VariableDecl{ - decls.NewVariable("input", decls.StringType), + decls.NewVariable("input", types.StringType), }, in: map[string]any{ "input": "kathmandu", @@ -853,7 +853,7 @@ func testData(t testing.TB) []testCase { name: "matches_error", expr: `input.matches(')k.*')`, vars: []*decls.VariableDecl{ - decls.NewVariable("input", decls.StringType), + decls.NewVariable("input", types.StringType), }, in: map[string]any{ "input": "kathmandu", @@ -870,7 +870,7 @@ func testData(t testing.TB) []testCase { types: []proto.Message{&proto3pb.TestAllTypes{}}, vars: []*decls.VariableDecl{ decls.NewVariable("pb3", - decls.ObjectType("google.expr.proto3.test.TestAllTypes")), + types.NewObjectType("google.expr.proto3.test.TestAllTypes")), }, in: map[string]any{ "pb3": &proto3pb.TestAllTypes{ @@ -889,7 +889,7 @@ func testData(t testing.TB) []testCase { types: []proto.Message{&proto3pb.TestAllTypes{}}, vars: []*decls.VariableDecl{ decls.NewVariable("pb3", - decls.ObjectType("google.expr.proto3.test.TestAllTypes")), + types.NewObjectType("google.expr.proto3.test.TestAllTypes")), }, in: map[string]any{ "pb3": &proto3pb.TestAllTypes{ @@ -909,8 +909,8 @@ func testData(t testing.TB) []testCase { name: "or_true_1st", expr: `ai == 20 || ar["foo"] == "bar"`, vars: []*decls.VariableDecl{ - decls.NewVariable("ai", decls.IntType), - decls.NewVariable("ar", decls.MapType(decls.StringType, decls.StringType)), + decls.NewVariable("ai", types.IntType), + decls.NewVariable("ar", types.NewMapType(types.StringType, types.StringType)), }, in: map[string]any{ "ai": 20, @@ -923,8 +923,8 @@ func testData(t testing.TB) []testCase { name: "or_true_2nd", expr: `ai == 20 || ar["foo"] == "bar"`, vars: []*decls.VariableDecl{ - decls.NewVariable("ai", decls.IntType), - decls.NewVariable("ar", decls.MapType(decls.StringType, decls.StringType)), + decls.NewVariable("ai", types.IntType), + decls.NewVariable("ar", types.NewMapType(types.StringType, types.StringType)), }, in: map[string]any{ "ai": 2, @@ -937,8 +937,8 @@ func testData(t testing.TB) []testCase { name: "or_false", expr: `ai == 20 || ar["foo"] == "bar"`, vars: []*decls.VariableDecl{ - decls.NewVariable("ai", decls.IntType), - decls.NewVariable("ar", decls.MapType(decls.StringType, decls.StringType)), + decls.NewVariable("ai", types.IntType), + decls.NewVariable("ar", types.NewMapType(types.StringType, types.StringType)), }, in: map[string]any{ "ai": 2, @@ -973,7 +973,7 @@ func testData(t testing.TB) []testCase { expr: `b.c.d != 10`, container: "a.b", vars: []*decls.VariableDecl{ - decls.NewVariable("a.b.c.d", decls.IntType), + decls.NewVariable("a.b.c.d", types.IntType), }, in: map[string]any{ "a.b.c.d": 9, @@ -1013,7 +1013,7 @@ func testData(t testing.TB) []testCase { && m.boolMap['val'] == true && m.boolMap['val'] != false`, vars: []*decls.VariableDecl{ - decls.NewVariable("m", decls.MapType(decls.StringType, decls.DynType)), + decls.NewVariable("m", types.NewMapType(types.StringType, types.DynType)), }, in: map[string]any{ "m": map[string]any{ @@ -1044,7 +1044,7 @@ func testData(t testing.TB) []testCase { && m.boolBool[true] && m.boolIface[false] == true`, vars: []*decls.VariableDecl{ - decls.NewVariable("m", decls.MapType(decls.StringType, decls.DynType)), + decls.NewVariable("m", types.NewMapType(types.StringType, types.DynType)), }, in: map[string]any{ "m": map[string]any{ @@ -1069,7 +1069,7 @@ func testData(t testing.TB) []testCase { && m.uint64Iface[3u] == -2.1 && m.uint64String[4u] == 'three'`, vars: []*decls.VariableDecl{ - decls.NewVariable("m", decls.MapType(decls.StringType, decls.DynType)), + decls.NewVariable("m", types.NewMapType(types.StringType, types.DynType)), }, in: map[string]any{ "m": map[string]any{ @@ -1095,7 +1095,7 @@ func testData(t testing.TB) []testCase { && m.boolList[1] != true && m.ifaceList[0] == {}`, vars: []*decls.VariableDecl{ - decls.NewVariable("m", decls.MapType(decls.StringType, decls.DynType)), + decls.NewVariable("m", types.NewMapType(types.StringType, types.DynType)), }, in: map[string]any{ "m": map[string]any{ @@ -1121,9 +1121,9 @@ func testData(t testing.TB) []testCase { container: "google.expr.proto3", types: []proto.Message{&proto3pb.TestAllTypes{}}, vars: []*decls.VariableDecl{ - decls.NewVariable("a.b", decls.MapType(decls.StringType, decls.BoolType)), - decls.NewVariable("pb3", decls.ObjectType("google.expr.proto3.test.TestAllTypes")), - decls.NewVariable("json", decls.MapType(decls.StringType, decls.DynType)), + decls.NewVariable("a.b", types.NewMapType(types.StringType, types.BoolType)), + decls.NewVariable("pb3", types.NewObjectType("google.expr.proto3.test.TestAllTypes")), + decls.NewVariable("json", types.NewMapType(types.StringType, types.DynType)), }, in: map[string]any{ "a.b": map[string]bool{ @@ -1166,7 +1166,7 @@ func testData(t testing.TB) []testCase { "a": &proto2pb.TestAllTypes{}, }, vars: []*decls.VariableDecl{ - decls.NewVariable("a", decls.ObjectType("google.expr.proto2.test.TestAllTypes")), + decls.NewVariable("a", types.NewObjectType("google.expr.proto2.test.TestAllTypes")), }, }, // Wrapper type nil or value test. @@ -1179,7 +1179,7 @@ func testData(t testing.TB) []testCase { types: []proto.Message{&proto3pb.TestAllTypes{}}, abbrevs: []string{"google.protobuf.Int32Value"}, vars: []*decls.VariableDecl{ - decls.NewVariable("a", decls.ObjectType("google.expr.proto3.test.TestAllTypes")), + decls.NewVariable("a", types.NewObjectType("google.expr.proto3.test.TestAllTypes")), }, in: map[string]any{ "a": &proto3pb.TestAllTypes{ @@ -1194,7 +1194,7 @@ func testData(t testing.TB) []testCase { container: "google.expr.proto3.test", types: []proto.Message{&proto3pb.TestAllTypes{}}, vars: []*decls.VariableDecl{ - decls.NewVariable("a", decls.ObjectType("google.expr.proto3.test.TestAllTypes")), + decls.NewVariable("a", types.NewObjectType("google.expr.proto3.test.TestAllTypes")), }, in: map[string]any{ "a": &proto3pb.TestAllTypes{ @@ -1210,7 +1210,7 @@ func testData(t testing.TB) []testCase { types: []proto.Message{&proto3pb.TestAllTypes_NestedMessage{}}, vars: []*decls.VariableDecl{ decls.NewVariable("a", - decls.ObjectType("google.expr.proto3.test.TestAllTypes.NestedMessage")), + types.NewObjectType("google.expr.proto3.test.TestAllTypes.NestedMessage")), }, attrs: &custAttrFactory{ AttributeFactory: NewAttributeFactory( @@ -1231,7 +1231,7 @@ func testData(t testing.TB) []testCase { expr: `json('{"hi":"world"}').hi == 'world'`, funcs: []*decls.FunctionDecl{ funcDecl(t, "json", - decls.Overload("json_string", []*decls.Type{decls.StringType}, decls.DynType, + decls.Overload("json_string", []*types.Type{types.StringType}, types.DynType, decls.UnaryBinding(func(val ref.Val) ref.Val { str, ok := val.(types.String) if !ok { @@ -1252,8 +1252,8 @@ func testData(t testing.TB) []testCase { name: "select_subsumed_field", expr: `a.b.c`, vars: []*decls.VariableDecl{ - decls.NewVariable("a.b.c", decls.IntType), - decls.NewVariable("a.b", decls.MapType(decls.StringType, decls.StringType)), + decls.NewVariable("a.b.c", types.IntType), + decls.NewVariable("a.b", types.NewMapType(types.StringType, types.StringType)), }, in: map[string]any{ "a.b.c": 10, @@ -1276,7 +1276,7 @@ func testData(t testing.TB) []testCase { unchecked: true, funcs: []*decls.FunctionDecl{ funcDecl(t, "try", - decls.Overload("try_dyn", []*decls.Type{decls.DynType}, decls.DynType, + decls.Overload("try_dyn", []*types.Type{types.DynType}, types.DynType, decls.OverloadIsNonStrict(), decls.UnaryBinding(func(arg ref.Val) ref.Val { if types.IsError(arg) { @@ -1296,8 +1296,8 @@ func testData(t testing.TB) []testCase { funcs: []*decls.FunctionDecl{ funcDecl(t, "try", decls.Overload("try_dyn", - []*decls.Type{decls.DynType, decls.DynType}, - decls.ListType(decls.DynType), + []*types.Type{types.DynType, types.DynType}, + types.NewListType(types.DynType), decls.OverloadIsNonStrict(), decls.BinaryBinding(func(arg0, arg1 ref.Val) ref.Val { if types.IsError(arg0) { @@ -1317,8 +1317,8 @@ func testData(t testing.TB) []testCase { funcs: []*decls.FunctionDecl{ funcDecl(t, "try", decls.Overload("try_dyn", - []*decls.Type{decls.DynType, decls.DynType, decls.DynType}, - decls.ListType(decls.DynType), + []*types.Type{types.DynType, types.DynType, types.DynType}, + types.NewListType(types.DynType), decls.OverloadIsNonStrict(), decls.FunctionBinding(func(args ...ref.Val) ref.Val { if types.IsError(args[0]) { @@ -1512,7 +1512,7 @@ func TestInterpreter_ProtoAttributeOpt(t *testing.T) { types: []proto.Message{&proto3pb.TestAllTypes{}}, vars: []*decls.VariableDecl{ decls.NewVariable("pb3", - decls.ObjectType("google.expr.proto3.test.TestAllTypes")), + types.NewObjectType("google.expr.proto3.test.TestAllTypes")), }, in: map[string]any{ "pb3": &proto3pb.TestAllTypes{ @@ -1609,7 +1609,7 @@ func TestInterpreter_InterruptableEval(t *testing.T) { tc := testCase{ expr: `items.map(i, i).map(i, i).size() != 0`, vars: []*decls.VariableDecl{ - decls.NewVariable("items", decls.ListType(decls.IntType)), + decls.NewVariable("items", types.NewListType(types.IntType)), }, in: map[string]any{ "items": items, @@ -1712,7 +1712,7 @@ func TestInterpreter_SetProto2PrimitiveFields(t *testing.T) { env.Add( varExprDecl(t, decls.NewVariable("input", - decls.ObjectType("google.expr.proto2.test.TestAllTypes")))) + types.NewObjectType("google.expr.proto2.test.TestAllTypes")))) checked, errors := checker.Check(parsed, src, env) if len(errors.GetErrors()) != 0 { t.Errorf(errors.ToDisplayString()) @@ -1765,7 +1765,7 @@ func TestInterpreter_MissingIdentInSelect(t *testing.T) { cont := testContainer("test") reg := newTestRegistry(t) env := newTestEnv(t, cont, reg) - env.Add(varExprDecl(t, decls.NewVariable("a.b", decls.DynType))) + env.Add(varExprDecl(t, decls.NewVariable("a.b", types.DynType))) checked, errors := checker.Check(parsed, src, env) if len(errors.GetErrors()) != 0 { t.Fatalf(errors.ToDisplayString()) diff --git a/interpreter/prune_test.go b/interpreter/prune_test.go index 004cd250..191c6eda 100644 --- a/interpreter/prune_test.go +++ b/interpreter/prune_test.go @@ -518,27 +518,27 @@ func testActivation(t *testing.T, in any) Activation { } func optionalDecls(t *testing.T) []*decls.FunctionDecl { - paramType := decls.TypeParamType("T") - optionalType := decls.OptionalType(paramType) + paramType := types.NewTypeParamType("T") + optionalType := types.NewOptionalType(paramType) return []*decls.FunctionDecl{ funcDecl(t, "optional.none", - decls.Overload("optional_none", []*decls.Type{}, optionalType, + decls.Overload("optional_none", []*types.Type{}, optionalType, decls.FunctionBinding(func(args ...ref.Val) ref.Val { return types.OptionalNone }), ), ), funcDecl(t, "optional.of", - decls.Overload("optional_of_value", []*decls.Type{paramType}, optionalType, + decls.Overload("optional_of_value", []*types.Type{paramType}, optionalType, decls.UnaryBinding(func(val ref.Val) ref.Val { return types.OptionalOf(val) }), ), ), funcDecl(t, "_[?_]", - decls.Overload("map_optindex_optional_value", []*decls.Type{ - decls.MapType(decls.TypeParamType("K"), paramType), - decls.TypeParamType("K"), + decls.Overload("map_optindex_optional_value", []*types.Type{ + types.NewMapType(types.NewTypeParamType("K"), paramType), + types.NewTypeParamType("K"), }, optionalType), ), } diff --git a/interpreter/runtimecost_test.go b/interpreter/runtimecost_test.go index 899e3062..77e8efe0 100644 --- a/interpreter/runtimecost_test.go +++ b/interpreter/runtimecost_test.go @@ -27,6 +27,7 @@ import ( "github.com/google/cel-go/common/containers" "github.com/google/cel-go/common/decls" "github.com/google/cel-go/common/overloads" + "github.com/google/cel-go/common/types" "github.com/google/cel-go/common/types/ref" "github.com/google/cel-go/parser" @@ -234,13 +235,13 @@ func (tc testCostEstimator) EstimateCallCost(function, overloadID string, target } func TestRuntimeCost(t *testing.T) { - allTypes := decls.ObjectType("google.expr.proto3.test.TestAllTypes") - allList := decls.ListType(allTypes) - intList := decls.ListType(decls.IntType) - nestedList := decls.ListType(allList) + allTypes := types.NewObjectType("google.expr.proto3.test.TestAllTypes") + allList := types.NewListType(allTypes) + intList := types.NewListType(types.IntType) + nestedList := types.NewListType(allList) - allMap := decls.MapType(decls.StringType, allTypes) - nestedMap := decls.MapType(decls.StringType, allMap) + allMap := types.NewMapType(types.StringType, allTypes) + nestedMap := types.NewMapType(types.StringType, allMap) cases := []struct { name string expr string @@ -268,14 +269,14 @@ func TestRuntimeCost(t *testing.T) { { name: "select: map", expr: `input['key']`, - vars: []*decls.VariableDecl{decls.NewVariable("input", decls.MapType(decls.StringType, decls.StringType))}, + vars: []*decls.VariableDecl{decls.NewVariable("input", types.NewMapType(types.StringType, types.StringType))}, want: 2, in: map[string]any{"input": map[string]string{"key": "v"}}, }, { name: "select: array index", expr: `input[0]`, - vars: []*decls.VariableDecl{decls.NewVariable("input", decls.ListType(decls.StringType))}, + vars: []*decls.VariableDecl{decls.NewVariable("input", types.NewListType(types.StringType))}, want: 2, in: map[string]any{"input": []string{"v"}}, }, @@ -297,21 +298,21 @@ func TestRuntimeCost(t *testing.T) { { name: "expr select: map", expr: `input['ke' + 'y']`, - vars: []*decls.VariableDecl{decls.NewVariable("input", decls.MapType(decls.StringType, decls.StringType))}, + vars: []*decls.VariableDecl{decls.NewVariable("input", types.NewMapType(types.StringType, types.StringType))}, want: 3, in: map[string]any{"input": map[string]string{"key": "v"}}, }, { name: "expr select: array index", expr: `input[3-3]`, - vars: []*decls.VariableDecl{decls.NewVariable("input", decls.ListType(decls.StringType))}, + vars: []*decls.VariableDecl{decls.NewVariable("input", types.NewListType(types.StringType))}, want: 3, in: map[string]any{"input": []string{"v"}}, }, { name: "select: field test only no has() cost", expr: `has(input.single_int32)`, - vars: []*decls.VariableDecl{decls.NewVariable("input", decls.ObjectType("google.expr.proto3.test.TestAllTypes"))}, + vars: []*decls.VariableDecl{decls.NewVariable("input", types.NewObjectType("google.expr.proto3.test.TestAllTypes"))}, want: 1, options: []CostTrackerOption{PresenceTestHasCost(false)}, in: map[string]any{ @@ -327,7 +328,7 @@ func TestRuntimeCost(t *testing.T) { { name: "select: field test only", expr: `has(input.single_int32)`, - vars: []*decls.VariableDecl{decls.NewVariable("input", decls.ObjectType("google.expr.proto3.test.TestAllTypes"))}, + vars: []*decls.VariableDecl{decls.NewVariable("input", types.NewObjectType("google.expr.proto3.test.TestAllTypes"))}, want: 2, in: map[string]any{ "input": &proto3pb.TestAllTypes{ @@ -383,7 +384,7 @@ func TestRuntimeCost(t *testing.T) { { name: "estimated function call", expr: `input.getFullYear()`, - vars: []*decls.VariableDecl{decls.NewVariable("input", decls.TimestampType)}, + vars: []*decls.VariableDecl{decls.NewVariable("input", types.TimestampType)}, want: 8, in: map[string]any{"input": time.Now()}, testFuncCost: true, @@ -428,7 +429,7 @@ func TestRuntimeCost(t *testing.T) { }, { name: "variable cost function", - vars: []*decls.VariableDecl{decls.NewVariable("input", decls.StringType)}, + vars: []*decls.VariableDecl{decls.NewVariable("input", types.StringType)}, expr: `input.matches('[0-9]')`, want: 103, in: map[string]any{"input": string(randSeq(500))}, @@ -453,10 +454,10 @@ func TestRuntimeCost(t *testing.T) { name: "or accumulated branch cost", expr: `a || b || c || d`, vars: []*decls.VariableDecl{ - decls.NewVariable("a", decls.BoolType), - decls.NewVariable("b", decls.BoolType), - decls.NewVariable("c", decls.BoolType), - decls.NewVariable("d", decls.BoolType), + decls.NewVariable("a", types.BoolType), + decls.NewVariable("b", types.BoolType), + decls.NewVariable("c", types.BoolType), + decls.NewVariable("d", types.BoolType), }, in: map[string]any{ "a": false, @@ -480,10 +481,10 @@ func TestRuntimeCost(t *testing.T) { name: "and accumulated branch cost", expr: `a && b && c && d`, vars: []*decls.VariableDecl{ - decls.NewVariable("a", decls.BoolType), - decls.NewVariable("b", decls.BoolType), - decls.NewVariable("c", decls.BoolType), - decls.NewVariable("d", decls.BoolType), + decls.NewVariable("a", types.BoolType), + decls.NewVariable("b", types.BoolType), + decls.NewVariable("c", types.BoolType), + decls.NewVariable("d", types.BoolType), }, in: map[string]any{ "a": true, @@ -565,14 +566,14 @@ func TestRuntimeCost(t *testing.T) { }, { name: "bytes to string conversion", - vars: []*decls.VariableDecl{decls.NewVariable("input", decls.BytesType)}, + vars: []*decls.VariableDecl{decls.NewVariable("input", types.BytesType)}, expr: `string(input)`, want: 51, in: map[string]any{"input": randSeq(500)}, }, { name: "string to bytes conversion", - vars: []*decls.VariableDecl{decls.NewVariable("input", decls.StringType)}, + vars: []*decls.VariableDecl{decls.NewVariable("input", types.StringType)}, expr: `bytes(input)`, want: 51, in: map[string]any{"input": string(randSeq(500))}, @@ -586,8 +587,8 @@ func TestRuntimeCost(t *testing.T) { name: "contains", expr: `input.contains(arg1)`, vars: []*decls.VariableDecl{ - decls.NewVariable("input", decls.StringType), - decls.NewVariable("arg1", decls.StringType), + decls.NewVariable("input", types.StringType), + decls.NewVariable("arg1", types.StringType), }, want: 2502, in: map[string]any{"input": string(randSeq(500)), "arg1": string(randSeq(500))}, @@ -596,7 +597,7 @@ func TestRuntimeCost(t *testing.T) { name: "matches", expr: `input.matches('\\d+a\\d+b')`, vars: []*decls.VariableDecl{ - decls.NewVariable("input", decls.StringType), + decls.NewVariable("input", types.StringType), }, want: 103, in: map[string]any{"input": string(randSeq(500)), "arg1": string(randSeq(500))}, @@ -605,8 +606,8 @@ func TestRuntimeCost(t *testing.T) { name: "startsWith", expr: `input.startsWith(arg1)`, vars: []*decls.VariableDecl{ - decls.NewVariable("input", decls.StringType), - decls.NewVariable("arg1", decls.StringType), + decls.NewVariable("input", types.StringType), + decls.NewVariable("arg1", types.StringType), }, want: 3, in: map[string]any{"input": "idc", "arg1": string(randSeq(500))}, @@ -615,8 +616,8 @@ func TestRuntimeCost(t *testing.T) { name: "endsWith", expr: `input.endsWith(arg1)`, vars: []*decls.VariableDecl{ - decls.NewVariable("input", decls.StringType), - decls.NewVariable("arg1", decls.StringType), + decls.NewVariable("input", types.StringType), + decls.NewVariable("arg1", types.StringType), }, want: 3, in: map[string]any{"input": "idc", "arg1": string(randSeq(500))}, @@ -625,7 +626,7 @@ func TestRuntimeCost(t *testing.T) { name: "size receiver", expr: `input.size()`, vars: []*decls.VariableDecl{ - decls.NewVariable("input", decls.StringType), + decls.NewVariable("input", types.StringType), }, want: 2, in: map[string]any{"input": "500", "arg1": "500"}, @@ -634,7 +635,7 @@ func TestRuntimeCost(t *testing.T) { name: "size", expr: `size(input)`, vars: []*decls.VariableDecl{ - decls.NewVariable("input", decls.StringType), + decls.NewVariable("input", types.StringType), }, want: 2, in: map[string]any{"input": "500", "arg1": "500"}, @@ -643,7 +644,7 @@ func TestRuntimeCost(t *testing.T) { name: "ternary eval", expr: `(x > 2 ? input1 : input2).all(y, true)`, vars: []*decls.VariableDecl{ - decls.NewVariable("x", decls.IntType), + decls.NewVariable("x", types.IntType), decls.NewVariable("input1", allList), decls.NewVariable("input2", allList), }, @@ -711,8 +712,8 @@ func TestRuntimeCost(t *testing.T) { name: "list concat", expr: `(list1 + list2).all(x, true)`, vars: []*decls.VariableDecl{ - decls.NewVariable("list1", decls.ListType(decls.IntType)), - decls.NewVariable("list2", decls.ListType(decls.IntType)), + decls.NewVariable("list1", types.NewListType(types.IntType)), + decls.NewVariable("list2", types.NewListType(types.IntType)), }, want: 4, in: map[string]any{"list1": []int{}, "list2": []int{}}, @@ -721,8 +722,8 @@ func TestRuntimeCost(t *testing.T) { name: "str concat", expr: `"abcdefg".contains(str1 + str2)`, vars: []*decls.VariableDecl{ - decls.NewVariable("str1", decls.StringType), - decls.NewVariable("str2", decls.StringType), + decls.NewVariable("str1", types.StringType), + decls.NewVariable("str2", types.StringType), }, want: 6, in: map[string]any{"str1": "val1", "str2": "val2222222"}, @@ -731,8 +732,8 @@ func TestRuntimeCost(t *testing.T) { name: "at limit", expr: `"abcdefg".contains(str1 + str2)`, vars: []*decls.VariableDecl{ - decls.NewVariable("str1", decls.StringType), - decls.NewVariable("str2", decls.StringType), + decls.NewVariable("str1", types.StringType), + decls.NewVariable("str2", types.StringType), }, in: map[string]any{"str1": "val1", "str2": "val2222222"}, limit: 6, @@ -742,8 +743,8 @@ func TestRuntimeCost(t *testing.T) { name: "above limit", expr: `"abcdefg".contains(str1 + str2)`, vars: []*decls.VariableDecl{ - decls.NewVariable("str1", decls.StringType), - decls.NewVariable("str2", decls.StringType), + decls.NewVariable("str1", types.StringType), + decls.NewVariable("str2", types.StringType), }, in: map[string]any{"str1": "val1", "str2": "val2222222"}, limit: 5,