Skip to content

Commit 285436e

Browse files
l46kokcopybara-github
authored andcommitted
Clear the source position for only the dangling macro expr ID instead of all exprs
PiperOrigin-RevId: 632228017
1 parent fbf7c27 commit 285436e

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

common/src/main/java/dev/cel/common/CelSource.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,6 @@ public Builder addPositions(long exprId, int position) {
261261
return this;
262262
}
263263

264-
@CanIgnoreReturnValue
265-
public Builder clearPositions() {
266-
this.positions.clear();
267-
return this;
268-
}
269-
270264
@CanIgnoreReturnValue
271265
public Builder removePositions(long exprId) {
272266
this.positions.remove(exprId);

parser/src/main/java/dev/cel/parser/Parser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ private CelExpr macroOrCall(
896896
ImmutableList<CelExpr> arguments = visitExprListContext(args);
897897
Optional<CelExpr> errorArg = arguments.stream().filter(ERROR::equals).findAny();
898898
if (errorArg.isPresent()) {
899-
sourceInfo.clearPositions();
899+
sourceInfo.removePositions(exprBuilder.id());
900900
// Any arguments passed in to the macro may fail parsing.
901901
// Stop the macro expansion in this case as the result of the macro will be a parse failure.
902902
return ERROR;

parser/src/test/java/dev/cel/parser/CelParserParameterizedTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ public void parser_errors() {
239239
runTest(PARSER, "TestAllTypes(){single_int32: 1, single_int64: 2}");
240240
runTest(PARSER, "{");
241241
runTest(PARSER, "t{>C}");
242+
runTest(PARSER, "has([(has((");
242243

243244
CelParser parserWithoutOptionalSupport =
244245
CelParserImpl.newBuilder()

parser/src/test/resources/parser_errors.baseline

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,15 @@ ERROR: <input>:1:5: mismatched input '}' expecting ':'
262262
| t{>C}
263263
| ....^
264264

265+
I: has([(has((
266+
=====>
267+
E: ERROR: <input>:1:4: invalid argument to has() macro
268+
| has([(has((
269+
| ...^
270+
ERROR: <input>:1:12: mismatched input '<EOF>' expecting {'[', '{', '(', '.', '-', '!', 'true', 'false', 'null', NUM_FLOAT, NUM_INT, NUM_UINT, STRING, BYTES, IDENTIFIER}
271+
| has([(has((
272+
| ...........^
273+
265274
I: a.?b && a[?b]
266275
=====>
267276
E: ERROR: <input>:1:2: unsupported syntax '.?'
@@ -287,4 +296,4 @@ E: ERROR: <input>:1:2: unsupported syntax '?'
287296
| .^
288297
ERROR: <input>:1:6: unsupported syntax '?'
289298
| [?a, ?b]
290-
| .....^
299+
| .....^

0 commit comments

Comments
 (0)