twrong_tupleconv.nim 452 B

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