tswap.nim 464 B

1234567891011121314151617181920212223242526272829303132333435
  1. discard """
  2. nimout: '''
  3. x.data = @[10]
  4. y = @[11]
  5. x.data = @[11]
  6. y = @[10]
  7. @[3, 2, 1]
  8. '''
  9. """
  10. # bug #2946
  11. proc testSwap(): int {.compiletime.} =
  12. type T = object
  13. data: seq[int]
  14. var x: T
  15. x.data = @[10]
  16. var y = @[11]
  17. echo "x.data = ", x.data
  18. echo "y = ", y
  19. swap(y, x.data)
  20. echo "x.data = ", x.data
  21. echo "y = ", y
  22. result = 99
  23. const something = testSwap()
  24. # bug #15463
  25. block:
  26. static:
  27. var s = @[1, 2, 3]
  28. swap(s[0], s[2])
  29. echo s