@@ -259,8 +259,13 @@ var (
259
259
260
260
// ExistsOneMacro expands "range.exists_one(var, predicate)", which is true if for exactly one
261
261
// element in range the predicate holds.
262
+ // Deprecated: Use ExistsOneMacroNew
262
263
ExistsOneMacro = NewReceiverMacro (operators .ExistsOne , 2 , MakeExistsOne )
263
264
265
+ // ExistsOneMacroNew expands "range.existsOne(var, predicate)", which is true if for exactly one
266
+ // element in range the predicate holds.
267
+ ExistsOneMacroNew = NewReceiverMacro ("existsOne" , 2 , MakeExistsOne )
268
+
264
269
// MapMacro expands "range.map(var, function)" into a comprehension which applies the function
265
270
// to each element in the range to produce a new list.
266
271
MapMacro = NewReceiverMacro (operators .Map , 2 , MakeMap )
@@ -280,6 +285,7 @@ var (
280
285
AllMacro ,
281
286
ExistsMacro ,
282
287
ExistsOneMacro ,
288
+ ExistsOneMacroNew ,
283
289
MapMacro ,
284
290
MapFilterMacro ,
285
291
FilterMacro ,
@@ -336,6 +342,9 @@ func MakeMap(eh ExprHelper, target ast.Expr, args []ast.Expr) (ast.Expr, *common
336
342
if ! found {
337
343
return nil , eh .NewError (args [0 ].ID (), "argument is not an identifier" )
338
344
}
345
+ if v == AccumulatorName {
346
+ return nil , eh .NewError (args [0 ].ID (), "iteration variable overwrites accumulator variable" )
347
+ }
339
348
340
349
var fn ast.Expr
341
350
var filter ast.Expr
@@ -366,6 +375,9 @@ func MakeFilter(eh ExprHelper, target ast.Expr, args []ast.Expr) (ast.Expr, *com
366
375
if ! found {
367
376
return nil , eh .NewError (args [0 ].ID (), "argument is not an identifier" )
368
377
}
378
+ if v == AccumulatorName {
379
+ return nil , eh .NewError (args [0 ].ID (), "iteration variable overwrites accumulator variable" )
380
+ }
369
381
370
382
filter := args [1 ]
371
383
init := eh .NewList ()
@@ -389,6 +401,9 @@ func makeQuantifier(kind quantifierKind, eh ExprHelper, target ast.Expr, args []
389
401
if ! found {
390
402
return nil , eh .NewError (args [0 ].ID (), "argument must be a simple name" )
391
403
}
404
+ if v == AccumulatorName {
405
+ return nil , eh .NewError (args [0 ].ID (), "iteration variable overwrites accumulator variable" )
406
+ }
392
407
393
408
var init ast.Expr
394
409
var condition ast.Expr
0 commit comments