Nim/tests/ccgbugs/twrong_tupleconv.nim
Miran ce152ed91f iterators: several small fixes (#11162)
* fix pairs, mpairs, mitems for cstring for JS backend
* add mutation check for pairs and mpairs for strings and seqs
* change the assertion message - modifying (changing elements) is not
  a problem, changing the length is
2019-05-04 23:02:50 +02:00

20 lines
450 B
Nim

# bug #1833
iterator myitems*[T](a: var seq[T]): var T {.inline.} =
## iterates over each item of `a` so that you can modify the yielded value.
var i = 0
let L = len(a)
while i < L:
yield a[i]
inc(i)
assert(len(a) == L, "the length of the seq changed while iterating over it")
# Works fine
var xs = @[1,2,3]
for x in myitems(xs):
inc x
# Tuples don't work
var ys = @[(1,"a"),(2,"b"),(3,"c")]
for y in myitems(ys):
inc y[0]