From 7e284e92a0420a2e311426b82c675034476feec5 Mon Sep 17 00:00:00 2001 From: CEL Dev Team Date: Wed, 9 Jul 2025 14:10:23 -0700 Subject: [PATCH] Add clarifying notes to CEL codelab exercise 4 solution. PiperOrigin-RevId: 781204887 --- codelab/solutions/exercise4.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/codelab/solutions/exercise4.cc b/codelab/solutions/exercise4.cc index f56789a4d..244fdac05 100644 --- a/codelab/solutions/exercise4.cc +++ b/codelab/solutions/exercise4.cc @@ -91,6 +91,9 @@ absl::StatusOr> MakeConfiguredCompiler() { // Codelab part 1: // Add a declaration for the map.contains(string, V) function. auto& checker_builder = builder->GetCheckerBuilder(); + // Note: we use MakeMemberOverloadDecl instead of MakeOverloadDecl + // because the function is receiver style, meaning that it is called as + // e1.f(e2) instead of f(e1, e2). CEL_ASSIGN_OR_RETURN( cel::FunctionDecl decl, cel::MakeFunctionDecl( @@ -100,6 +103,8 @@ absl::StatusOr> MakeConfiguredCompiler() { cel::MapType(checker_builder.arena(), cel::StringType(), cel::TypeParamType("V")), cel::StringType(), cel::TypeParamType("V")))); + // Note: we use MergeFunction instead of AddFunction because we are adding + // an overload to an already declared function with the same name. CEL_RETURN_IF_ERROR(checker_builder.MergeFunction(decl)); return builder->Build(); } @@ -135,7 +140,7 @@ class Evaluator { if (bool value; result.GetValue(&value)) { return value; - } else if (const CelError * value; result.GetValue(&value)) { + } else if (const CelError* value; result.GetValue(&value)) { return *value; } else { return absl::InvalidArgumentError(