tcopying.nim 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. discard """
  2. output: '''123
  3. 2 9
  4. 2 9
  5. 1 124
  6. true false
  7. 100 300 100
  8. 1
  9. 1
  10. '''
  11. """
  12. type MyArray = array[1, int]
  13. proc changeArray(a: var MyArray) =
  14. a = [123]
  15. var a: MyArray
  16. changeArray(a)
  17. echo a[0]
  18. # bug #4703
  19. # Test 1
  20. block:
  21. let ary1 = [1, 2, 3]
  22. var ary2 = ary1
  23. ary2[1] = 9
  24. echo ary1[1], " ", ary2[1]
  25. # Test 2
  26. block:
  27. type TestObj = ref object of RootObj
  28. ary2: array[3, int]
  29. let ary1 = [1, 2, 3]
  30. var obj = TestObj(ary2: ary1)
  31. obj.ary2[1] = 9
  32. echo ary1[1], " ", obj.ary2[1]
  33. block:
  34. type TestObj = object
  35. x, y: int
  36. let obj = TestObj(x: 1, y: 2)
  37. var s = @[obj]
  38. s[0].x += 123
  39. echo obj.x, " ", s[0].x
  40. block:
  41. var nums = {1, 2, 3, 4}
  42. let obj = (n: nums)
  43. nums.incl 5
  44. echo (5 in nums), " ", (5 in obj.n)
  45. block:
  46. let tup1 = (a: 100)
  47. var tup2 = (t: (t2: tup1))
  48. var tup3 = tup1
  49. tup2.t.t2.a = 300
  50. echo tup1.a, " ", tup2.t.t2.a, " ", tup3.a
  51. block:
  52. proc foo(arr: array[2, int]) =
  53. var s = @arr
  54. s[0] = 500
  55. var nums = [1, 2]
  56. foo(nums)
  57. echo nums[0]
  58. proc bug9674 =
  59. var b = @[1,2,3]
  60. var a = move(b)
  61. echo a[0]
  62. bug9674()