summary refs log tree commit diff stats
path: root/tests/arc
diff options
context:
space:
mode:
authorringabout <43030857+ringabout@users.noreply.github.com>2022-09-28 19:12:08 +0800
committerGitHub <noreply@github.com>2022-09-28 13:12:08 +0200
commitfe8feb46c6b69d2a2b63c83af88d0f9f03a31435 (patch)
tree134e9e803a0e083b6d1418d8c7ff4896b8b518f7 /tests/arc
parent95614089ac9ddd61de834a2fb1454b5d159acb35 (diff)
downloadNim-fe8feb46c6b69d2a2b63c83af88d0f9f03a31435.tar.gz
fixes #19457 seqs are not properly updated in loop with ARC/ORC (#19922)
* test CI

* fixes #19457

* add comments

Co-authored-by: sandytypical <43030857+xflywind@users.noreply.github.com>
Diffstat (limited to 'tests/arc')
-rw-r--r--tests/arc/t19457.nim16
-rw-r--r--tests/arc/topt_refcursors.nim37
2 files changed, 38 insertions, 15 deletions
diff --git a/tests/arc/t19457.nim b/tests/arc/t19457.nim
new file mode 100644
index 000000000..78447ce82
--- /dev/null
+++ b/tests/arc/t19457.nim
@@ -0,0 +1,16 @@
+discard """
+  matrix: "--gc:refc; --gc:arc"
+"""
+
+# bug #19457
+proc gcd(x, y: seq[int]): seq[int] =
+    var
+      a = x
+      b = y
+    while b[0] > 0:
+      let c = @[a[0] mod b[0]]
+      a = b
+      b = c
+    return a
+
+doAssert gcd(@[1], @[2]) == @[1]
\ No newline at end of file
diff --git a/tests/arc/topt_refcursors.nim b/tests/arc/topt_refcursors.nim
index f097150a3..c13d81bad 100644
--- a/tests/arc/topt_refcursors.nim
+++ b/tests/arc/topt_refcursors.nim
@@ -5,21 +5,28 @@ discard """
 
 var
   it_cursor
-  jt_cursor
-it_cursor = root
-block :tmp:
-  while (
-    not (it_cursor == nil)):
-    echo [it_cursor.s]
-    it_cursor = it_cursor.ri
-jt_cursor = root
-block :tmp_1:
-  while (
-    not (jt_cursor == nil)):
-    var ri_1_cursor
-    ri_1_cursor = jt_cursor.ri
-    echo [jt_cursor.s]
-    jt_cursor = ri_1_cursor
+  jt
+try:
+  it_cursor = root
+  block :tmp:
+    while (
+      not (it_cursor == nil)):
+      echo [it_cursor.s]
+      it_cursor = it_cursor.ri
+  `=copy`(jt, root)
+  block :tmp_1:
+    while (
+      not (jt == nil)):
+      var ri_1
+      try:
+        `=copy`(ri_1, jt.ri)
+        echo [jt.s]
+        `=sink`(jt, ri_1)
+        wasMoved(ri_1)
+      finally:
+        `=destroy`(ri_1)
+finally:
+  `=destroy`(jt)
 -- end of expandArc ------------------------'''
 """