tsimple_array_checks.nim 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. discard """
  2. sortoutput: true
  3. output: '''
  4. 0
  5. 1
  6. 2
  7. 3
  8. 4
  9. 5
  10. 6
  11. 7
  12. 8
  13. 9
  14. Hello 1
  15. Hello 2
  16. Hello 3
  17. Hello 4
  18. Hello 5
  19. Hello 6
  20. '''
  21. """
  22. # bug #2287
  23. import threadPool
  24. # If `nums` is an array instead of seq,
  25. # NONE of the iteration ways below work (including high / len-1)
  26. let nums = @[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  27. proc log(n:int) =
  28. echo n
  29. proc main =
  30. parallel:
  31. for n in nums: # Error: cannot prove: i <= len(nums) + -1
  32. spawn log(n)
  33. #for i in 0 ..< nums.len: # Error: cannot prove: i <= len(nums) + -1
  34. #for i in 0 .. nums.len-1: # WORKS!
  35. #for i in 0 ..< nums.len: # WORKS!
  36. # spawn log(nums[i])
  37. # Array needs explicit size to work, probably related to issue #2287
  38. #const a: array[0..5, int] = [1,2,3,4,5,6]
  39. #const a = [1,2,3,4,5,6] # Doesn't work
  40. const a = @[1,2,3,4,5,6] # Doesn't work
  41. proc f(n: int) = echo "Hello ", n
  42. proc maino =
  43. parallel:
  44. # while loop doesn't work:
  45. var i = 0
  46. while i < a.high:
  47. #for i in countup(0, a.high-1, 2):
  48. spawn f(a[i])
  49. spawn f(a[i+1])
  50. i += 2
  51. maino() # Doesn't work outside a proc
  52. when true:
  53. main()
  54. block two:
  55. proc f(a: openArray[int]) =
  56. discard
  57. proc main() =
  58. var a: array[0..9, int] = [0,1,2,3,4,5,6,7,8,9]
  59. parallel:
  60. spawn f(a[0..2])
  61. main()