tasyncintemplate.nim 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. discard """
  2. output: '''
  3. 42
  4. 43
  5. 43
  6. 1
  7. 2
  8. 3
  9. 4
  10. '''
  11. """
  12. # xxx move to tests/async/tasyncintemplate.nim
  13. import asyncdispatch
  14. block: # bug #16159
  15. template foo() =
  16. proc temp(): Future[int] {.async.} = return 42
  17. proc tempVoid(): Future[void] {.async.} = echo await temp()
  18. foo()
  19. waitFor tempVoid()
  20. block: # aliasing `void`
  21. template foo() =
  22. type Foo = void
  23. proc temp(): Future[int] {.async.} = return 43
  24. proc tempVoid(): Future[Foo] {.async.} = echo await temp()
  25. proc tempVoid2() {.async.} = echo await temp()
  26. foo()
  27. waitFor tempVoid()
  28. waitFor tempVoid2()
  29. block: # sanity check
  30. template foo() =
  31. proc bad(): int {.async.} = discard
  32. doAssert not compiles(bad())
  33. block: # bug #16786
  34. block:
  35. proc main(a: int|string)=
  36. proc bar(b: int|string) = echo b
  37. bar(a)
  38. main(1)
  39. block:
  40. proc main(a: int) : Future[void] {.async.} =
  41. proc bar(b: int): Future[void] {.async.} = echo b
  42. await bar(a)
  43. waitFor main(2)
  44. block:
  45. proc main(a: int) : Future[void] {.async.} =
  46. proc bar(b: int | string): Future[void] {.async.} = echo b
  47. await bar(a)
  48. waitFor main(3)
  49. block:
  50. # bug
  51. proc main(a: int|string) =
  52. proc bar(b: int): Future[void] {.async.} = echo b
  53. waitFor bar(a)
  54. main(4)