tdefer1.nim 360 B

123456789101112131415161718192021222324252627282930313233343536
  1. discard """
  2. output: '''hi
  3. 1
  4. hi
  5. 2
  6. B
  7. A'''
  8. """
  9. # bug #1742
  10. import strutils
  11. let x = try: parseInt("133a")
  12. except: -1
  13. finally: echo "hi"
  14. template atFuncEnd =
  15. defer:
  16. echo "A"
  17. defer:
  18. echo "B"
  19. template testB(): untyped =
  20. let a = 0
  21. defer: echo "hi"
  22. a
  23. proc main =
  24. atFuncEnd()
  25. echo 1
  26. let i = testB()
  27. echo 2
  28. main()