t12785.nim 709 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. discard """
  2. cmd: '''nim c --newruntime $file'''
  3. output: '''copied
  4. copied
  5. 2
  6. destroyed
  7. destroyed
  8. copied
  9. copied
  10. 2
  11. destroyed
  12. destroyed'''
  13. """
  14. type
  15. ObjWithDestructor = object
  16. a: int
  17. proc `=destroy`(self: var ObjWithDestructor) =
  18. echo "destroyed"
  19. proc `=`(self: var ObjWithDestructor, other: ObjWithDestructor) =
  20. echo "copied"
  21. proc test(a: range[0..1], arg: ObjWithDestructor) =
  22. var iteration = 0
  23. while true:
  24. {.computedGoto.}
  25. let
  26. b = int(a) * 2
  27. c = a
  28. d = arg
  29. e = arg
  30. discard c
  31. discard d
  32. discard e
  33. inc iteration
  34. case a
  35. of 0:
  36. assert false
  37. of 1:
  38. echo b
  39. if iteration == 2:
  40. break
  41. test(1, ObjWithDestructor())