summary refs log tree commit diff stats
path: root/tests/vm
diff options
context:
space:
mode:
authorAndreas Rumpf <rumpf_a@web.de>2016-04-04 01:41:14 +0200
committerAndreas Rumpf <rumpf_a@web.de>2016-04-04 01:41:14 +0200
commit86e79f5cec118587c7e52f614c245176cf480597 (patch)
treedb6d9825a07a7c8a3d01573cf4a6dfcafe405d9a /tests/vm
parentcb3a38afa2de4401af55fbb7b6050f499b182bf4 (diff)
downloadNim-86e79f5cec118587c7e52f614c245176cf480597.tar.gz
fixes #3804
Diffstat (limited to 'tests/vm')
-rw-r--r--tests/vm/twrong_concat.nim28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/vm/twrong_concat.nim b/tests/vm/twrong_concat.nim
new file mode 100644
index 000000000..538ea2527
--- /dev/null
+++ b/tests/vm/twrong_concat.nim
@@ -0,0 +1,28 @@
+discard """
+  output: '''success'''
+"""
+
+# bug #3804
+
+#import sequtils
+
+type AnObj = ref object
+  field: string
+
+#proc aBug(objs: seq[AnObj]) {.compileTime.} =
+#  discard objs.mapIt(it.field & " bug")
+
+proc sameBug(objs: seq[AnObj]) {.compileTime.} =
+  var strSeq = newSeq[string](objs.len)
+  strSeq[0] = objs[0].field & " bug"
+
+static:
+  var objs: seq[AnObj] = @[]
+  objs.add(AnObj(field: "hello"))
+
+  sameBug(objs)
+  # sameBug(objs)
+  echo objs[0].field
+  assert(objs[0].field == "hello") # fails, because (objs[0].field == "hello bug") - mutated!
+
+echo "success"