tbracketinstantiation.nim 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. discard """
  2. nimout: '''
  3. type
  4. Bob = object
  5. type
  6. Another = object
  7. '''
  8. """
  9. block: # issue #22645
  10. type
  11. Opt[T] = object
  12. FutureBase = ref object of RootObj
  13. Future[T] = ref object of FutureBase ## Typed future.
  14. internalValue: T ## Stored value
  15. template err[T](E: type Opt[T]): E = E()
  16. proc works(): Future[Opt[int]] {.stackTrace: off, gcsafe, raises: [].} =
  17. var chronosInternalRetFuture: FutureBase
  18. template result(): untyped {.used.} =
  19. Future[Opt[int]](chronosInternalRetFuture).internalValue
  20. result = err(type(result))
  21. proc breaks(): Future[Opt[int]] {.stackTrace: off, gcsafe, raises: [].} =
  22. var chronosInternalRetFuture: FutureBase
  23. template result(): untyped {.used.} =
  24. cast[Future[Opt[int]]](chronosInternalRetFuture).internalValue
  25. result = err(type(result))
  26. import macros
  27. block: # issue #16118
  28. macro thing(name: static[string]) =
  29. result = newStmtList(
  30. nnkTypeSection.newTree(
  31. nnkTypeDef.newTree(
  32. ident(name),
  33. newEmptyNode(),
  34. nnkObjectTy.newTree(
  35. newEmptyNode(),
  36. newEmptyNode(),
  37. nnkRecList.newTree()))))
  38. template foo(name: string): untyped =
  39. thing(name)
  40. expandMacros:
  41. foo("Bob")
  42. block:
  43. expandMacros:
  44. foo("Another")
  45. block: # issue #19670
  46. type
  47. Past[Z] = object
  48. OpenObject = object
  49. macro rewriter(prc: untyped): untyped =
  50. prc.body.add(nnkCall.newTree(
  51. prc.params[0]
  52. ))
  53. prc
  54. macro macroAsync(name, restype: untyped): untyped =
  55. quote do:
  56. proc `name`(): Past[seq[`restype`]] {.rewriter.} = discard
  57. macroAsync(testMacro, OpenObject)
  58. import asyncdispatch
  59. block: # issue #11838 long
  60. type
  61. R[P] = object
  62. updates: seq[P]
  63. D[T, P] = ref object
  64. ps: seq[P]
  65. t: T
  66. proc newD[T, P](ps: seq[P], t: T): D[T, P] =
  67. D[T, P](ps: ps, t: t)
  68. proc loop[T, P](d: D[T, P]) =
  69. var results = newSeq[Future[R[P]]](10)
  70. let d = newD[string, int](@[1], "")
  71. d.loop()
  72. block: # issue #11838 minimal
  73. type R[T] = object
  74. proc loop[T]() =
  75. discard newSeq[R[R[T]]]()
  76. loop[int]()