tlet.nim 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. discard """
  2. joinable: false
  3. """
  4. {.experimental: "strictDefs".}
  5. proc bar(x: out string) =
  6. x = "abc"
  7. template moe = # bug #21043
  8. try:
  9. discard
  10. except ValueError as e:
  11. echo(e.msg)
  12. template moe0 {.dirty.} = # bug #21043
  13. try:
  14. discard
  15. except ValueError as e:
  16. echo(e.msg)
  17. proc foo() =
  18. block:
  19. let x: string
  20. if true:
  21. x = "abc"
  22. else:
  23. x = "def"
  24. doAssert x == "abc"
  25. block:
  26. let y: string
  27. bar(y)
  28. doAssert y == "abc"
  29. block:
  30. let x: string
  31. if true:
  32. x = "abc"
  33. discard "abc"
  34. else:
  35. x = "def"
  36. discard "def"
  37. doAssert x == "abc"
  38. block: #
  39. let x {.used.} : int
  40. block: #
  41. let x: float
  42. x = 1.234
  43. doAssert x == 1.234
  44. block:
  45. try:
  46. discard
  47. except ValueError as e:
  48. echo(e.msg)
  49. moe()
  50. moe0()
  51. static: foo()
  52. foo()
  53. proc foo2 =
  54. when nimvm:
  55. discard
  56. else:
  57. let x = 1
  58. doAssert x == 1
  59. when false:
  60. discard
  61. else:
  62. let y = 2
  63. doAssert y == 2
  64. const e = 1
  65. when e == 0:
  66. discard
  67. elif e == 1:
  68. let z = 3
  69. else:
  70. discard
  71. doAssert z == 3
  72. foo2()
  73. # bug #24472
  74. template bar1314(): bool =
  75. let hello = true
  76. hello
  77. template foo1314*(val: bool): bool =
  78. when nimvm:
  79. val
  80. else:
  81. val
  82. proc test() = # Doesn't fail when top level
  83. # Original code is calling `unlikely` which has a `nimvm` branch
  84. let s = foo1314(bar1314())
  85. doAssert s
  86. test()