summary refs log tree commit diff stats
path: root/tests/parallel
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2015-03-12 00:27:49 +0100
committerAraq <rumpf_a@web.de>2015-03-12 01:45:14 +0100
commit5a21892da0d16cc0fb321dadb17140a4808b0c17 (patch)
treea40eae85e4182999eb3f60525ffed1b823b62dd8 /tests/parallel
parent970e98718dfe0c494369bcb42b12d8cf7ace3f7c (diff)
downloadNim-5a21892da0d16cc0fb321dadb17140a4808b0c17.tar.gz
fixes #2287
Diffstat (limited to 'tests/parallel')
-rw-r--r--tests/parallel/tsimple_array_checks.nim41
1 files changed, 41 insertions, 0 deletions
diff --git a/tests/parallel/tsimple_array_checks.nim b/tests/parallel/tsimple_array_checks.nim
new file mode 100644
index 000000000..9874d3299
--- /dev/null
+++ b/tests/parallel/tsimple_array_checks.nim
@@ -0,0 +1,41 @@
+# bug #2287
+
+import threadPool
+
+# If `nums` is an array instead of seq,
+# NONE of the iteration ways below work (including high / len-1)
+let nums = @[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
+
+proc log(n:int) =
+  echo n
+
+proc main =
+  parallel:
+    for n in nums: # Error: cannot prove: i <= len(nums) + -1
+      spawn log(n)
+    #for i in 0 .. <nums.len: # Error: cannot prove: i <= len(nums) + -1
+    #for i in 0 .. nums.len-1: # WORKS!
+    #for i in 0 .. <nums.len: # WORKS!
+    #  spawn log(nums[i])
+
+# Array needs explicit size to work, probably related to issue #2287
+#const a: array[0..5, int] = [1,2,3,4,5,6]
+
+#const a = [1,2,3,4,5,6] # Doesn't work
+const a = @[1,2,3,4,5,6] # Doesn't work
+proc f(n: int) = echo "Hello ", n
+
+proc maino =
+  parallel:
+    # while loop doesn't work:
+    var i = 0
+    while i < a.high:
+      #for i in countup(0, a.high-1, 2):
+      spawn f(a[i])
+      spawn f(a[i+1])
+      i += 2
+
+maino() # Doesn't work outside a proc
+
+when isMainModule:
+  main()