tptrarrayderef.nim 901 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. discard """
  2. output: "OK"
  3. """
  4. var
  5. arr = [1,2,3]
  6. arrp = addr(arr)
  7. sss = @[4,5,6,7]
  8. sssp = addr(sss)
  9. ra = new(array[3, int])
  10. raa = [11,12,13]
  11. #bug #3586
  12. proc mutate[T](arr:openarray[T], brr: openArray[T]) =
  13. for i in 0..arr.len-1:
  14. doAssert(arr[i] == brr[i])
  15. mutate(arr, arr)
  16. #bug #2240
  17. proc f(a: openarray[int], b: openArray[int]) =
  18. for i in 0..a.len-1:
  19. doAssert(a[i] == b[i])
  20. var a = [7,8,9]
  21. var p = addr a
  22. f(p[], a)
  23. f(sssp[], sss)
  24. ra[0] = 11
  25. ra[1] = 12
  26. ra[2] = 13
  27. f(ra[], raa)
  28. #bug #2240b
  29. proc fillBuffer(buf: var openarray[char]) =
  30. for i in 0..buf.len-1:
  31. buf[i] = chr(i)
  32. proc fillSeqBuffer(b: ref seq[char]) =
  33. fillBuffer(b[])
  34. proc getFilledBuffer(sz: int): ref seq[char] =
  35. let s : ref seq[char] = new(seq[char])
  36. s[] = newSeq[char](sz)
  37. fillBuffer(s[])
  38. return s
  39. let aa = getFilledBuffer(3)
  40. for i in 0..aa[].len-1:
  41. doAssert(aa[i] == chr(i))
  42. echo "OK"