@@ -164,12 +164,15 @@ absl::optional<Expr> ExpandExistsOneMacro(MacroExprFactory& factory,
164164 }
165165 auto init = factory.NewIntConst (0 );
166166 auto condition = factory.NewBoolConst (true );
167- auto step =
168- factory.NewCall (CelOperator::CONDITIONAL, std::move (args[1 ]),
169- factory.NewCall (CelOperator::ADD, factory.NewAccuIdent (),
170- factory.NewIntConst (1 )),
171- factory.NewAccuIdent ());
172- auto result = factory.NewCall (CelOperator::EQUALS, factory.NewAccuIdent (),
167+ auto accu_ident = factory.NewAccuIdent ();
168+ auto const_1 = factory.NewIntConst (1 );
169+ auto inc_step = factory.NewCall (CelOperator::ADD, std::move (accu_ident),
170+ std::move (const_1));
171+
172+ auto step = factory.NewCall (CelOperator::CONDITIONAL, std::move (args[1 ]),
173+ std::move (inc_step), factory.NewAccuIdent ());
174+ accu_ident = factory.NewAccuIdent ();
175+ auto result = factory.NewCall (CelOperator::EQUALS, std::move (accu_ident),
173176 factory.NewIntConst (1 ));
174177 return factory.NewComprehension (args[0 ].ident_expr ().name (),
175178 std::move (target), factory.AccuVarName (),
@@ -200,9 +203,11 @@ absl::optional<Expr> ExpandMap2Macro(MacroExprFactory& factory, Expr& target,
200203 }
201204 auto init = factory.NewList ();
202205 auto condition = factory.NewBoolConst (true );
203- auto step = factory.NewCall (
204- CelOperator::ADD, factory.NewAccuIdent (),
205- factory.NewList (factory.NewListElement (std::move (args[1 ]))));
206+ auto accu_ref = factory.NewAccuIdent ();
207+ auto accu_update =
208+ factory.NewList (factory.NewListElement (std::move (args[1 ])));
209+ auto step = factory.NewCall (CelOperator::ADD, std::move (accu_ref),
210+ std::move (accu_update));
206211 return factory.NewComprehension (args[0 ].ident_expr ().name (),
207212 std::move (target), factory.AccuVarName (),
208213 std::move (init), std::move (condition),
@@ -231,9 +236,11 @@ absl::optional<Expr> ExpandMap3Macro(MacroExprFactory& factory, Expr& target,
231236 }
232237 auto init = factory.NewList ();
233238 auto condition = factory.NewBoolConst (true );
234- auto step = factory.NewCall (
235- CelOperator::ADD, factory.NewAccuIdent (),
236- factory.NewList (factory.NewListElement (std::move (args[2 ]))));
239+ auto accu_ref = factory.NewAccuIdent ();
240+ auto accu_update =
241+ factory.NewList (factory.NewListElement (std::move (args[2 ])));
242+ auto step = factory.NewCall (CelOperator::ADD, std::move (accu_ref),
243+ std::move (accu_update));
237244 step = factory.NewCall (CelOperator::CONDITIONAL, std::move (args[1 ]),
238245 std::move (step), factory.NewAccuIdent ());
239246 return factory.NewComprehension (args[0 ].ident_expr ().name (),
@@ -266,9 +273,11 @@ absl::optional<Expr> ExpandFilterMacro(MacroExprFactory& factory, Expr& target,
266273
267274 auto init = factory.NewList ();
268275 auto condition = factory.NewBoolConst (true );
269- auto step = factory.NewCall (
270- CelOperator::ADD, factory.NewAccuIdent (),
271- factory.NewList (factory.NewListElement (std::move (args[0 ]))));
276+ auto accu_ref = factory.NewAccuIdent ();
277+ auto accu_update =
278+ factory.NewList (factory.NewListElement (std::move (args[0 ])));
279+ auto step = factory.NewCall (CelOperator::ADD, std::move (accu_ref),
280+ std::move (accu_update));
272281 step = factory.NewCall (CelOperator::CONDITIONAL, std::move (args[1 ]),
273282 std::move (step), factory.NewAccuIdent ());
274283 return factory.NewComprehension (std::move (name), std::move (target),
0 commit comments