Skip to content

Commit

Permalink
Pre-requisite fixes for optional_type conformance tests (#917)
Browse files Browse the repository at this point in the history
* Fix duplicate IDs in optMap and optFlatMap macros

Signed-off-by: Justin King <jcking@google.com>

* Enable support for `optional_types` in conformance server

Signed-off-by: Justin King <jcking@google.com>

---------

Signed-off-by: Justin King <jcking@google.com>
  • Loading branch information
jcking committed Mar 28, 2024
1 parent 14757df commit 6305c71
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cel/library.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ func optMap(meh MacroExprFactory, target ast.Expr, args []ast.Expr) (ast.Expr, *
meh.NewList(),
unusedIterVar,
varName,
meh.NewMemberCall(valueFunc, target),
meh.NewMemberCall(valueFunc, meh.Copy(target)),
meh.NewLiteral(types.False),
meh.NewIdent(varName),
mapExpr,
Expand All @@ -430,7 +430,7 @@ func optFlatMap(meh MacroExprFactory, target ast.Expr, args []ast.Expr) (ast.Exp
meh.NewList(),
unusedIterVar,
varName,
meh.NewMemberCall(valueFunc, target),
meh.NewMemberCall(valueFunc, meh.Copy(target)),
meh.NewLiteral(types.False),
meh.NewIdent(varName),
mapExpr,
Expand Down
5 changes: 4 additions & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (s *ConformanceServer) Parse(ctx context.Context, in *confpb.ParseRequest)
if in.DisableMacros {
parseOptions = append(parseOptions, cel.ClearMacros())
}
parseOptions = append(parseOptions, cel.OptionalTypes())
env, _ := cel.NewEnv(parseOptions...)
past, iss := env.Parse(in.CelSource)
resp := confpb.ParseResponse{}
Expand Down Expand Up @@ -75,6 +76,7 @@ func (s *ConformanceServer) Check(ctx context.Context, in *confpb.CheckRequest)
checkOptions = append(checkOptions, cel.Declarations(in.TypeEnv...))
checkOptions = append(checkOptions, cel.Types(&test2pb.TestAllTypes{}))
checkOptions = append(checkOptions, cel.Types(&test3pb.TestAllTypes{}))
checkOptions = append(checkOptions, cel.OptionalTypes())
env, _ := cel.NewCustomEnv(checkOptions...)

// Check the expression.
Expand Down Expand Up @@ -254,5 +256,6 @@ var evalEnv *cel.Env
func init() {
evalEnv, _ = cel.NewEnv(
cel.Types(&test2pb.TestAllTypes{}, &test3pb.TestAllTypes{}),
cel.EagerlyValidateDeclarations(true))
cel.EagerlyValidateDeclarations(true),
cel.OptionalTypes())
}

0 comments on commit 6305c71

Please sign in to comment.