system/excpt: check if the exception is not nil before pop (#18247)

In CPS we would consume an exception in the except branch by stashing it
into a local then remove the exception from Nim environment so as not to
leak it to other code that would be running before the continuation
continues

However since popCurrentException() assumes that the exception always
exist, removing the exception from an except branch will cause a
SIGSEGV to happen. This commit fixes that.
This commit is contained in:
alaviss 2021-06-14 11:26:12 -05:00 • committed by GitHub
commit 0adb47aa15
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View file

@ -6,3 +6,10 @@ let ex = newException(CatchableError, "test")
setCurrentException(ex)
doAssert getCurrentException().msg == ex.msg
doAssert getCurrentExceptionMsg() == ex.msg
setCurrentException(nil)
try:
raise newException(CatchableError, "test2")
except:
setCurrentException(nil)
doAssert getCurrentException() == nil