status-im / nim-chronos

Chronos - An efficient library for asynchronous programming
https://status-im.github.io/nim-chronos/
Apache License 2.0
362 stars 51 forks source link

Nested defer/finally not called #288

Closed arnetheduck closed 2 years ago

arnetheduck commented 2 years ago
import chronos

proc p1(a: int) {.async.} =
   try:                             # remove this ok
      try:
         echo a
         await sleepAsync(100)      # remove this ok
         return                     # remove this ok
      finally:
         echo "finally"
   except:
      discard

proc p2(a: int) {.async.} =
   try:                             # remove this ok
      defer:
         echo "defer"
      await sleepAsync(100)      # remove this ok
      return                     # remove this ok
   except:
      discard

when isMainModule:
   waitFor p1(10)
   waitFor p2(10)

This is the same issue as upstream https://github.com/nim-lang/Nim/issues/19911 cc @Araq @yglukhov

cheatfate commented 2 years ago

Please note, this is not a nim-chronos issue, its Nim compiler's issue.

Menduist commented 2 years ago

Fixed in nim devel: https://github.com/nim-lang/Nim/pull/19933#event-6967963630 Will be backported to 1.6