Skip to content

Commit 6c9df94

Browse files
jnthntatumcopybara-github
authored andcommitted
Add variable for dyn type (e.g. type(dyn(1)) == dyn)
PiperOrigin-RevId: 688186304
1 parent e47ba71 commit 6c9df94

2 files changed

Lines changed: 14 additions & 4 deletions

File tree

checker/standard_library.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,12 @@ Type TypeTimestampType() {
116116
return *kInstance;
117117
}
118118

119+
Type TypeDynType() {
120+
static absl::NoDestructor<Type> kInstance(
121+
TypeType(BuiltinsArena(), DynType()));
122+
return *kInstance;
123+
}
124+
119125
Type TypeListType() {
120126
static absl::NoDestructor<Type> kInstance(
121127
TypeType(BuiltinsArena(), ListOfA()));
@@ -998,6 +1004,9 @@ absl::Status AddTimeFunctions(TypeCheckerBuilder& builder) {
9981004
}
9991005

10001006
absl::Status AddTypeConstantVariables(TypeCheckerBuilder& builder) {
1007+
CEL_RETURN_IF_ERROR(
1008+
builder.AddVariable(MakeVariableDecl(builtin::kDyn, TypeDynType())));
1009+
10011010
CEL_RETURN_IF_ERROR(
10021011
builder.AddVariable(MakeVariableDecl("bool", TypeBoolType())));
10031012

checker/standard_library_test.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,14 @@ TEST_P(StdlibTypeVarDefinitionTest, DefinesTypeConstants) {
125125
const auto& checked_impl = AstImpl::CastFromPublicAst(*checked_ast);
126126
EXPECT_THAT(checked_impl.GetReference(1),
127127
Pointee(Property(&Reference::name, GetParam())));
128+
EXPECT_THAT(checked_impl.GetType(1), Property(&AstType::has_type, true));
128129
}
129130

130131
INSTANTIATE_TEST_SUITE_P(StdlibTypeVarDefinitions, StdlibTypeVarDefinitionTest,
131-
::testing::Values("bool", "int", "uint", "double",
132-
"string", "bytes", "list", "map",
133-
"duration", "timestamp", "null_type",
134-
"type"),
132+
::testing::Values("bool", "bytes", "double",
133+
"duration", "dyn", "int", "list",
134+
"map", "null_type", "string",
135+
"timestamp", "type", "uint"),
135136
[](const auto& info) -> std::string {
136137
return info.param;
137138
});

0 commit comments

Comments
 (0)