summary refs log tree commit diff stats
path: root/tests/iter/tshallowcopy_closures.nim
diff options
context:
space:
mode:
Diffstat (limited to 'tests/iter/tshallowcopy_closures.nim')
-rw-r--r--tests/iter/tshallowcopy_closures.nim36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/iter/tshallowcopy_closures.nim b/tests/iter/tshallowcopy_closures.nim
new file mode 100644
index 000000000..06b04a788
--- /dev/null
+++ b/tests/iter/tshallowcopy_closures.nim
@@ -0,0 +1,36 @@
+discard """
+  matrix: "--mm:refc"
+  ccodecheck: "!@('{' \\s* 'NI HEX3Astate;' \\s* '}')"
+  output: '''
+a1 10
+a1 9
+'''
+"""
+
+# bug #1803
+type TaskFn = iterator (): float
+
+iterator a1(): float {.closure.} =
+    var k = 10
+    while k > 0:
+        echo "a1 ", k
+        dec k
+        yield 1.0
+
+
+iterator a2(): float {.closure.} =
+    var k = 15
+    while k > 0:
+        echo "a2 ", k
+        dec k
+        yield 2.0
+
+var
+  x = a1
+  y = a2
+  z: TaskFn
+
+discard x()
+shallowCopy(z, x)
+shallowCopy(z, y)
+discard x()