tcomputedgotocopy.nim 642 B

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