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
5 changes: 3 additions & 2 deletions runtime/src/main/java/dev/cel/runtime/ResolvedOverload.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ default boolean canHandle(Object[] arguments) {
}

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

Expand Down
31 changes: 31 additions & 0 deletions runtime/src/test/java/dev/cel/runtime/CelResolvedOverloadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,35 @@ public void canHandle_nonMatchingTypes_returnsFalse() {
public void canHandle_nonMatchingArgCount_returnsFalse() {
assertThat(getIncrementIntOverload().canHandle(new Object[] {1L, 2L})).isFalse();
}

@Test
public void canHandle_nonStrictOverload_returnsTrue() {
CelResolvedOverload nonStrictOverload =
CelResolvedOverload.of(
"non_strict",
(args) -> {
return false;
},
/* isStrict= */ false,
Long.class,
Long.class);
assertThat(
nonStrictOverload.canHandle(
new Object[] {new RuntimeException(), CelUnknownSet.create()}))
.isTrue();
}

@Test
public void canHandle_nonStrictOverload_returnsFalse() {
CelResolvedOverload nonStrictOverload =
CelResolvedOverload.of(
"non_strict",
(args) -> {
return false;
},
/* isStrict= */ false,
Long.class,
Long.class);
assertThat(nonStrictOverload.canHandle(new Object[] {new RuntimeException(), "Foo"})).isFalse();
}
}