tcompiles.nim 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. discard """
  2. matrix: "--warningAsError:ProveInit --warningAsError:Uninit"
  3. """
  4. {.experimental: "strictdefs".}
  5. type Test = object
  6. id: int
  7. proc foo {.noreturn.} = discard
  8. block:
  9. proc test(x: bool): Test =
  10. if x:
  11. foo()
  12. else:
  13. foo()
  14. block:
  15. proc test(x: bool): Test =
  16. if x:
  17. result = Test()
  18. else:
  19. foo()
  20. discard test(true)
  21. block:
  22. proc test(x: bool): Test =
  23. if x:
  24. result = Test()
  25. else:
  26. return Test()
  27. discard test(true)
  28. block:
  29. proc test(x: bool): Test =
  30. if x:
  31. return Test()
  32. else:
  33. return Test()
  34. discard test(true)
  35. block:
  36. proc test(x: bool): Test =
  37. if x:
  38. result = Test()
  39. else:
  40. result = Test()
  41. return
  42. discard test(true)
  43. block:
  44. proc test(x: bool): Test =
  45. if x:
  46. result = Test()
  47. return
  48. else:
  49. raise newException(ValueError, "unreachable")
  50. discard test(true)
  51. # bug #21615
  52. # bug #16735
  53. block:
  54. type Test {.requiresInit.} = object
  55. id: int
  56. proc bar(): int =
  57. raise newException(CatchableError, "error")
  58. proc test(): Test =
  59. raise newException(CatchableError, "")
  60. template catchError(body) =
  61. var done = false
  62. try:
  63. body
  64. except CatchableError:
  65. done = true
  66. doAssert done
  67. catchError:
  68. echo test()
  69. catchError:
  70. echo bar()
  71. block:
  72. proc foo(x: ptr int) =
  73. discard
  74. proc main =
  75. var s: int
  76. foo(addr s)
  77. main()