Skip to content

Commit 5f4b90e

Browse files
l46kokcopybara-github
authored andcommitted
Do not re-use ID twice in exists_one macro
PiperOrigin-RevId: 629510077
1 parent 3ff9beb commit 5f4b90e

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,20 +170,22 @@ private static Optional<CelExpr> expandExistsOneMacro(
170170
return Optional.of(reportArgumentError(exprFactory, arg0));
171171
}
172172
CelExpr arg1 = checkNotNull(arguments.get(1));
173-
CelExpr zeroExpr = exprFactory.newIntLiteral(0);
174-
CelExpr oneExpr = exprFactory.newIntLiteral(1);
175-
CelExpr accuInit = zeroExpr;
173+
CelExpr accuInit = exprFactory.newIntLiteral(0);
176174
CelExpr condition = exprFactory.newBoolLiteral(true);
177175
CelExpr step =
178176
exprFactory.newGlobalCall(
179177
Operator.CONDITIONAL.getFunction(),
180178
arg1,
181179
exprFactory.newGlobalCall(
182-
Operator.ADD.getFunction(), exprFactory.newIdentifier(ACCUMULATOR_VAR), oneExpr),
180+
Operator.ADD.getFunction(),
181+
exprFactory.newIdentifier(ACCUMULATOR_VAR),
182+
exprFactory.newIntLiteral(1)),
183183
exprFactory.newIdentifier(ACCUMULATOR_VAR));
184184
CelExpr result =
185185
exprFactory.newGlobalCall(
186-
Operator.EQUALS.getFunction(), exprFactory.newIdentifier(ACCUMULATOR_VAR), oneExpr);
186+
Operator.EQUALS.getFunction(),
187+
exprFactory.newIdentifier(ACCUMULATOR_VAR),
188+
exprFactory.newIntLiteral(1));
187189
return Optional.of(
188190
exprFactory.fold(
189191
arg0.ident().name(), target, ACCUMULATOR_VAR, accuInit, condition, step, result));

parser/src/test/resources/parser.baseline

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -739,21 +739,21 @@ P: __comprehension__(
739739
// Init
740740
0^#5:int64#,
741741
// LoopCondition
742-
true^#7:bool#,
742+
true^#6:bool#,
743743
// LoopStep
744744
_?_:_(
745745
f^#4:Expr.Ident#,
746746
_+_(
747-
__result__^#8:Expr.Ident#,
748-
1^#6:int64#
747+
__result__^#7:Expr.Ident#,
748+
1^#8:int64#
749749
)^#9:Expr.Call#,
750750
__result__^#10:Expr.Ident#
751751
)^#11:Expr.Call#,
752752
// Result
753753
_==_(
754754
__result__^#12:Expr.Ident#,
755-
1^#6:int64#
756-
)^#13:Expr.Call#)^#14:Expr.Comprehension#
755+
1^#13:int64#
756+
)^#14:Expr.Call#)^#15:Expr.Comprehension#
757757
L: __comprehension__(
758758
// Variable
759759
v,
@@ -764,21 +764,21 @@ L: __comprehension__(
764764
// Init
765765
0^#5[1,12]#,
766766
// LoopCondition
767-
true^#7[1,12]#,
767+
true^#6[1,12]#,
768768
// LoopStep
769769
_?_:_(
770770
f^#4[1,16]#,
771771
_+_(
772-
__result__^#8[1,12]#,
773-
1^#6[1,12]#
772+
__result__^#7[1,12]#,
773+
1^#8[1,12]#
774774
)^#9[1,12]#,
775775
__result__^#10[1,12]#
776776
)^#11[1,12]#,
777777
// Result
778778
_==_(
779779
__result__^#12[1,12]#,
780-
1^#6[1,12]#
781-
)^#13[1,12]#)^#14[1,12]#
780+
1^#13[1,12]#
781+
)^#14[1,12]#)^#15[1,12]#
782782
M: m^#1:Expr.Ident#.exists_one(
783783
v^#3:Expr.Ident#,
784784
f^#4:Expr.Ident#

0 commit comments

Comments
 (0)