tpragmas_misc.nim 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ##[
  2. tests for misc pragmas that don't need a separate file
  3. ]##
  4. block:
  5. static: doAssert not defined(tpragmas_misc_def)
  6. {.undef(tpragmas_misc_def).} # works even if not set
  7. static: doAssert not defined(tpragmas_misc_def)
  8. {.define(tpragmas_misc_def).}
  9. static: doAssert defined(tpragmas_misc_def)
  10. {.undef(tpragmas_misc_def).}
  11. static: doAssert not defined(tpragmas_misc_def)
  12. block: # (partial fix) bug #15920
  13. block: # var template pragmas don't work in templates
  14. template foo(lhs, typ, expr) =
  15. let lhs = expr
  16. proc fun1()=
  17. let a {.foo.} = 1
  18. template fun2()=
  19. let a {.foo.} = 1
  20. fun1() # ok
  21. fun2() # WAS bug
  22. template foo2() = discard # distractor (template or other symbol kind)
  23. block:
  24. template foo2(lhs, typ, expr) =
  25. let lhs = expr
  26. proc fun1()=
  27. let a {.foo2.} = 1
  28. template fun2()=
  29. let a {.foo2.} = 1
  30. fun1() # ok
  31. when false: # bug: Error: invalid pragma: foo2
  32. fun2()
  33. block: # proc template pragmas don't work in templates
  34. # adapted from $nim/lib/std/private/since.nim
  35. # case without overload
  36. template since3(version: (int, int), body: untyped) {.dirty.} =
  37. when (NimMajor, NimMinor) >= version:
  38. body
  39. when false: # bug
  40. template fun3(): int {.since3: (1, 3).} = 12
  41. block: # ditto, w
  42. # case with overload
  43. template since2(version: (int, int), body: untyped) {.dirty.} =
  44. when (NimMajor, NimMinor) >= version:
  45. body
  46. template since2(version: (int, int, int), body: untyped) {.dirty.} =
  47. when (NimMajor, NimMinor, NimPatch) >= version:
  48. body
  49. when false: # bug
  50. template fun3(): int {.since2: (1, 3).} = 12
  51. when true: # D20210801T100514:here
  52. from macros import genSym
  53. block:
  54. template fn() =
  55. var ret {.gensym.}: int # must special case template pragmas so it doesn't get confused
  56. discard ret
  57. fn()
  58. static: discard genSym()