Skip to content

Commit 01ac8a5

Browse files
l46kokcopybara-github
authored andcommitted
Fix conformance test case around receiver function names containing reserved keywords for parsed-only case
PiperOrigin-RevId: 955950135
1 parent 8bfc4c7 commit 01ac8a5

2 files changed

Lines changed: 28 additions & 16 deletions

File tree

conformance/src/test/java/dev/cel/conformance/BUILD.bazel

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,10 @@ _TESTS_TO_SKIP_PLANNER = [
147147
"string_ext/format",
148148
"string_ext/format_errors",
149149

150-
# TODO: Check behavior for go/cpp
150+
# TODO: This is actually a user experience degradation.
151+
# Not worth fixing until we see a concrete need.
151152
"basic/functions/unbound_is_runtime_error",
152153

153-
# Skip until fixed.
154-
"parse/receiver_function_names",
155-
156154
# Type inference edgecases around null(able) assignability.
157155
# These type check, but resolve to a different type.
158156
# list(int), want list(wrapper(int))

runtime/src/main/java/dev/cel/runtime/planner/ProgramPlanner.java

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package dev.cel.runtime.planner;
1616

17+
import static com.google.common.base.Preconditions.checkNotNull;
18+
1719
import com.google.auto.value.AutoValue;
1820
import com.google.common.base.Strings;
1921
import com.google.common.collect.ImmutableList;
@@ -293,17 +295,24 @@ private PlannedInterpretable planCall(CelExpr expr, PlannerContext ctx) {
293295
}
294296

295297
if (resolvedOverload == null) {
296-
if (!lateBoundFunctionNames.contains(functionName)) {
298+
boolean isLateBound = lateBoundFunctionNames.contains(functionName);
299+
// For type-checked ASTs, functions that are not explicitly registered as late-bound
300+
// must be resolved at plan time.
301+
// For parsed-only ASTs or late-bound functions, defer overload resolution to runtime.
302+
if (ctx.isChecked() && !isLateBound) {
297303
CelReference reference = ctx.referenceMap().get(expr.id());
298-
if (reference != null) {
304+
if (reference != null && !reference.overloadIds().isEmpty()) {
299305
throw new CelOverloadNotFoundException(functionName, reference.overloadIds());
300306
} else {
301307
throw new CelOverloadNotFoundException(functionName);
302308
}
303309
}
304310

305311
ImmutableList<String> overloadIds = ImmutableList.of();
306-
if (resolvedFunction.overloadId().isPresent()) {
312+
CelReference reference = ctx.referenceMap().get(expr.id());
313+
if (reference != null && !reference.overloadIds().isEmpty()) {
314+
overloadIds = reference.overloadIds();
315+
} else if (resolvedFunction.overloadId().isPresent()) {
307316
overloadIds = ImmutableList.of(resolvedFunction.overloadId().get());
308317
}
309318

@@ -628,16 +637,23 @@ private static Builder newBuilder() {
628637
}
629638

630639
static final class PlannerContext {
631-
private final ImmutableMap<Long, CelReference> referenceMap;
632-
private final ImmutableMap<Long, CelType> typeMap;
640+
private final CelAbstractSyntaxTree ast;
633641
private final HashMap<String, Integer> localVars = new HashMap<>();
634642

643+
CelAbstractSyntaxTree ast() {
644+
return ast;
645+
}
646+
635647
ImmutableMap<Long, CelReference> referenceMap() {
636-
return referenceMap;
648+
return ast.getReferenceMap();
637649
}
638650

639651
ImmutableMap<Long, CelType> typeMap() {
640-
return typeMap;
652+
return ast.getTypeMap();
653+
}
654+
655+
boolean isChecked() {
656+
return ast.isChecked();
641657
}
642658

643659
private void pushLocalVars(String... names) {
@@ -670,14 +686,12 @@ private boolean isLocalVar(String name) {
670686
return localVars.containsKey(name);
671687
}
672688

673-
private PlannerContext(
674-
ImmutableMap<Long, CelReference> referenceMap, ImmutableMap<Long, CelType> typeMap) {
675-
this.referenceMap = referenceMap;
676-
this.typeMap = typeMap;
689+
private PlannerContext(CelAbstractSyntaxTree ast) {
690+
this.ast = checkNotNull(ast);
677691
}
678692

679693
static PlannerContext create(CelAbstractSyntaxTree ast) {
680-
return new PlannerContext(ast.getReferenceMap(), ast.getTypeMap());
694+
return new PlannerContext(ast);
681695
}
682696
}
683697

0 commit comments

Comments
 (0)