Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import dev.cel.common.types.CelType;
import dev.cel.common.types.CelTypeProvider;
import dev.cel.common.types.EnumType;
import dev.cel.common.types.SimpleType;
import dev.cel.common.types.TypeType;
import dev.cel.common.values.CelValue;
import dev.cel.common.values.CelValueConverter;
Expand Down Expand Up @@ -85,6 +86,12 @@ public Object resolve(GlobalResolver ctx, ExecutionFrame frame) {
if (type != null) {
if (qualifiers.isEmpty()) {
// Resolution of a fully qualified type name: foo.bar.baz
if (type instanceof TypeType) {
// Coalesce all type(foo) "type" into a sentinel runtime type to allow for
// erasure based type comparisons
return TypeType.create(SimpleType.DYN);
}

return TypeType.create(type);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,18 @@ public void planIdent_typeLiteral(@TestParameter TypeLiteralTestCase testCase) t
assertThat(result).isEqualTo(testCase.type);
}

@Test
public void planIdent_typeLiteral_equality(@TestParameter TypeLiteralTestCase testCase)
throws Exception {
// ex: type(bool) == type, type(TestAllTypes) == type
CelAbstractSyntaxTree ast = compile(String.format("type(%s) == type", testCase.expression));
Program program = PLANNER.plan(ast);

boolean result = (boolean) program.eval();

assertThat(result).isTrue();
}

@Test
public void plan_ident_missingAttribute_throws() throws Exception {
CelAbstractSyntaxTree ast = compile("int_var");
Expand Down
Loading