tasync_gcunsafe.nim 825 B

12345678910111213141516171819202122232425262728293031
  1. discard """
  2. errormsg: "'anotherGCSafeAsyncProc (Async)' is not GC-safe as it calls 'asyncGCUnsafeProc'"
  3. cmd: "nim c --threads:on $file"
  4. file: "asyncmacro.nim"
  5. """
  6. doAssert compileOption("threads"), "this test will not do anything useful without --threads:on"
  7. import asyncdispatch
  8. var globalDummy: ref int
  9. proc gcUnsafeProc() =
  10. if not globalDummy.isNil:
  11. echo globalDummy[]
  12. proc asyncExplicitlyGCSafeProc() {.gcsafe, async.} =
  13. echo "hi"
  14. proc asyncImplicitlyGCSafeProc() {.async.} =
  15. echo "hi"
  16. proc asyncGCUnsafeProc() {.async.} =
  17. gcUnsafeProc()
  18. proc anotherGCSafeAsyncProc() {.async, gcsafe.} =
  19. # We should be able to call other gcsafe procs
  20. await asyncExplicitlyGCSafeProc()
  21. await asyncImplicitlyGCSafeProc()
  22. # But we can't call gcunsafe procs
  23. await asyncGCUnsafeProc()