t9440.nim 683 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. discard """
  2. matrix: "--gc:refc; --gc:orc; --gc:arc"
  3. output: '''
  4. ()
  5. Destroyed
  6. ()
  7. Destroyed
  8. ()
  9. Destroyed
  10. end
  11. -------------------------
  12. ()
  13. Destroyed
  14. end
  15. '''
  16. """
  17. # bug #9440
  18. block:
  19. type
  20. X = object
  21. proc `=destroy`(x: var X) =
  22. echo "Destroyed"
  23. proc main() =
  24. for x in 0 .. 2:
  25. var obj = X()
  26. echo obj
  27. # The destructor call is invoked after "end" is printed
  28. echo "end"
  29. main()
  30. echo "-------------------------"
  31. block:
  32. type
  33. X = object
  34. proc `=destroy`(x: var X) =
  35. echo "Destroyed"
  36. proc main() =
  37. block:
  38. var obj = X()
  39. echo obj
  40. # The destructor is not called when obj goes out of scope
  41. echo "end"
  42. main()