Skip to content

Commit

Permalink
Fix standard function 'type' to accept a parameter type of TypeParamT…
Browse files Browse the repository at this point in the history
…ype instead of Dyn

PiperOrigin-RevId: 597349307
  • Loading branch information
l46kok authored and copybara-github committed Jan 10, 2024
1 parent 7c4c5ee commit 870c594
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion checker/src/main/java/dev/cel/checker/Standard.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ private static ImmutableList<CelFunctionDecl> coreFunctionDeclarations() {
CelFunctionDecl.newFunctionDeclaration(
"type",
CelOverloadDecl.newGlobalOverload(
"type", "returns type of value", TypeType.create(SimpleType.DYN), typeParamA)));
"type", "returns type of value", TypeType.create(typeParamA), typeParamA)));

// Conversions to int
celFunctionDeclBuilder.add(
Expand Down
2 changes: 2 additions & 0 deletions checker/src/test/java/dev/cel/checker/ExprCheckerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,8 @@ public void unexpectedAggregateMapError() throws Exception {
public void types() throws Exception {
source = "list == type([1]) && map == type({1:2u})";
runTest();
source = "{}.map(c,[c,type(c)])";
runTest();
}

// Enum Values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ _&&_(
_==_(
type(
make_abs()~abs^make_abs
)~type(dyn)^type,
)~type(abs)^type,
abs~type(abs)^abs
)~bool^equals,
make_abs()~abs^make_abs.as_bool()~bool^as_bool
)~bool^logical_and

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ _&&_(
1~int
]~list(int)
)~vector(int)^vector
)~type(dyn)^type,
)~type(vector(int))^type,
vector(
dyn~type(dyn)^dyn
)~type(vector(dyn))^vector
Expand All @@ -31,4 +31,3 @@ _&&_(
1~int
)~bool^equals
)~bool^logical_and

2 changes: 1 addition & 1 deletion checker/src/test/resources/standardEnvDump.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ declare timestamp {
}
declare type {
value type(dyn)
function type (A) -> type(dyn)
function type (A) -> type(A)
}
declare uint {
value type(uint)
Expand Down
31 changes: 29 additions & 2 deletions checker/src/test/resources/types.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,42 @@ _&&_(
[
1~int
]~list(int)
)~type(dyn)^type
)~type(list(int))^type
)~bool^equals,
_==_(
map~type(map(dyn, dyn))^map,
type(
{
1~int:2u~uint
}~map(int, uint)
)~type(dyn)^type
)~type(map(int, uint))^type
)~bool^equals
)~bool^logical_and

Source: {}.map(c,[c,type(c)])
=====>
__comprehension__(
// Variable
c,
// Target
{}~map(dyn, dyn),
// Accumulator
__result__,
// Init
[]~list(list(dyn)),
// LoopCondition
true~bool,
// LoopStep
_+_(
__result__~list(list(dyn))^__result__,
[
[
c~dyn^c,
type(
c~dyn^c
)~type(dyn)^type
]~list(dyn)
]~list(list(dyn))
)~list(list(dyn))^add_list,
// Result
__result__~list(list(dyn))^__result__)~list(list(dyn))

0 comments on commit 870c594

Please sign in to comment.