Skip to content

Commit 9083e06

Browse files
l46kokcopybara-github
authored andcommitted
Fix argument matching to validate all args for non-strict functions
PiperOrigin-RevId: 828548887
1 parent 2eed0fe commit 9083e06

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

runtime/src/main/java/dev/cel/runtime/ResolvedOverload.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ default boolean canHandle(Object[] arguments) {
7272
}
7373

7474
if (arg instanceof Exception || arg instanceof CelUnknownSet) {
75+
// Only non-strict functions can accept errors/unknowns as arguments to a function
7576
if (!isStrict()) {
76-
// Only non-strict functions can accept errors/unknowns as arguments to a function
77-
return true;
77+
// Skip assignability check below, but continue to validate remaining args
78+
continue;
7879
}
7980
}
8081

runtime/src/test/java/dev/cel/runtime/CelResolvedOverloadTest.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,35 @@ public void canHandle_nonMatchingTypes_returnsFalse() {
6565
public void canHandle_nonMatchingArgCount_returnsFalse() {
6666
assertThat(getIncrementIntOverload().canHandle(new Object[] {1L, 2L})).isFalse();
6767
}
68+
69+
@Test
70+
public void canHandle_nonStrictOverload_returnsTrue() {
71+
CelResolvedOverload nonStrictOverload =
72+
CelResolvedOverload.of(
73+
"non_strict",
74+
(args) -> {
75+
return false;
76+
},
77+
/* isStrict= */ false,
78+
Long.class,
79+
Long.class);
80+
assertThat(
81+
nonStrictOverload.canHandle(
82+
new Object[] {new RuntimeException(), CelUnknownSet.create()}))
83+
.isTrue();
84+
}
85+
86+
@Test
87+
public void canHandle_nonStrictOverload_returnsFalse() {
88+
CelResolvedOverload nonStrictOverload =
89+
CelResolvedOverload.of(
90+
"non_strict",
91+
(args) -> {
92+
return false;
93+
},
94+
/* isStrict= */ false,
95+
Long.class,
96+
Long.class);
97+
assertThat(nonStrictOverload.canHandle(new Object[] {new RuntimeException(), "Foo"})).isFalse();
98+
}
6899
}

0 commit comments

Comments
 (0)