tseqops.nim 755 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. discard """
  2. output: '''(x: 0, y: 0)
  3. (x: 5, y: 0)
  4. @[(x: "2", y: 4), (x: "4", y: 5), (x: "4", y: 5)]
  5. @[(a: "3", b: 3), (a: "1", b: 1), (a: "2", b: 2)]
  6. '''
  7. """
  8. # bug #4139
  9. type
  10. TestO = object
  11. x, y: int
  12. proc onLoad() =
  13. var test: seq[TestO] = @[]
  14. var foo = TestO(x: 0, y: 0)
  15. test.add(foo)
  16. foo.x = 5
  17. echo(test[0])
  18. echo foo
  19. onLoad()
  20. # 'setLen' bug (part of bug #5933)
  21. type MyObj = object
  22. x: cstring
  23. y: int
  24. proc foo(x: var seq[MyObj]) =
  25. let L = x.len
  26. x.setLen L + 1
  27. x[L] = x[1]
  28. var s = @[MyObj(x: "2", y: 4), MyObj(x: "4", y: 5)]
  29. foo(s)
  30. echo s
  31. # bug #5933
  32. import sequtils
  33. type
  34. Test = object
  35. a: cstring
  36. b: int
  37. var test = @[Test(a: "1", b: 1), Test(a: "2", b: 2)]
  38. test.insert(@[Test(a: "3", b: 3)], 0)
  39. echo test