Skip to content

Commit 53e58a7

Browse files
TristonianJoneskyessenov
authored andcommitted
Implement the dyn() identity function
PiperOrigin-RevId: 346846292
1 parent f9988db commit 53e58a7

4 files changed

Lines changed: 13 additions & 2 deletions

File tree

conformance/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ cc_binary(
8989
"--skip_test=timestamps/duration_conversions/toType_duration,toString_duration",
9090
# TODO(issues/78): Missing bytes() conversion functions
9191
"--skip_test=conversions/bytes",
92-
# TODO(issues/80): Missing dyn() conversion functions
93-
"--skip_test=conversions/dyn/dyn_heterogeneous_list",
9492
# TODO(issues/81): Conversion functions for int(), uint() which can be
9593
# uncommented when the spec changes to truncation rather than rounding.
9694
"--skip_test=conversions/int/double_nearest,double_nearest_neg,double_half_away_neg,double_half_away_pos",

eval/public/builtin_func_registrar.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,12 @@ absl::Status RegisterConversionFunctions(CelFunctionRegistry* registry,
12371237
builtin::kDuration, false, CreateDurationFromString, registry);
12381238
if (!status.ok()) return status;
12391239

1240+
// dyn() identity function.
1241+
// TODO(issues/102): strip dyn() function references at type-check time.
1242+
status = FunctionAdapter<CelValue, CelValue>::CreateAndRegister(
1243+
builtin::kDyn, false,
1244+
[](Arena*, CelValue value) -> CelValue { return value; }, registry);
1245+
12401246
status = RegisterIntConversionFunctions(registry, options);
12411247
if (!status.ok()) return status;
12421248

eval/public/builtin_func_test.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,12 @@ TEST_F(BuiltinsTest, TestDoubleConversionError_stringInvalid) {
718718
TestTypeConversionError(builtin::kDouble, CelValue::CreateString(&invalid));
719719
}
720720

721+
TEST_F(BuiltinsTest, TestDynConversions) {
722+
TestTypeConverts(builtin::kDyn, CelValue::CreateDouble(100.1), 100.1);
723+
TestTypeConverts(builtin::kDyn, CelValue::CreateInt64(100L), 100L);
724+
TestTypeConverts(builtin::kDyn, CelValue::CreateUint64(100UL), 100UL);
725+
}
726+
721727
TEST_F(BuiltinsTest, TestIntConversions_int) {
722728
TestTypeConverts(builtin::kInt, CelValue::CreateInt64(100L), 100L);
723729
}

eval/public/cel_builtins.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ constexpr char kMilliseconds[] = "getMilliseconds";
7272
// Type conversions
7373
// TODO(issues/23): Add other type conversion methods.
7474
constexpr char kDouble[] = "double";
75+
constexpr char kDyn[] = "dyn";
7576
constexpr char kInt[] = "int";
7677
constexpr char kString[] = "string";
7778
constexpr char kType[] = "type";

0 commit comments

Comments
 (0)