summary refs log tree commit diff stats
path: root/tests/ccgbugs
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2015-01-18 20:49:56 +0100
committerAraq <rumpf_a@web.de>2015-01-18 20:49:56 +0100
commit71d3cccb07bb824df10c5dd90493aaf16350e171 (patch)
treef5dc3922815bd4939b8c935ac51c9ed9ec549b30 /tests/ccgbugs
parentbb3dae3a9196abbe663ffbdf6f065eba86d6c548 (diff)
downloadNim-71d3cccb07bb824df10c5dd90493aaf16350e171.tar.gz
fixes #1833
Diffstat (limited to 'tests/ccgbugs')
-rw-r--r--tests/ccgbugs/twrong_tupleconv.nim20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/ccgbugs/twrong_tupleconv.nim b/tests/ccgbugs/twrong_tupleconv.nim
new file mode 100644
index 000000000..68413e96e
--- /dev/null
+++ b/tests/ccgbugs/twrong_tupleconv.nim
@@ -0,0 +1,20 @@
+# 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, "seq modified 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]
+