Reset closure iter exception before rethrowing

This commit is contained in:
Yuriy Glukhov 2019-08-16 17:26:00 +02:00
commit 721ca3e830
2 changed files with 6 additions and 8 deletions

View file

@ -90,9 +90,6 @@
# :unrollFinally = true # :unrollFinally = true
# goto nearestFinally (or -1 if not exists) # goto nearestFinally (or -1 if not exists)
# #
# Every finally block calls closureIterEndFinally() upon its successful
# completion.
#
# Example: # Example:
# #
# try: # try:
@ -126,6 +123,7 @@
# if :curExc.isNil: # if :curExc.isNil:
# return :tmpResult # return :tmpResult
# else: # else:
# closureIterSetupExc(nil)
# raise # raise
# state = -1 # Goto next state. In this case we just exit # state = -1 # Goto next state. In this case we just exit
# break :stateLoop # break :stateLoop
@ -809,10 +807,11 @@ proc newEndFinallyNode(ctx: var Ctx, info: TLineInfo): PNode =
let retStmt = newTree(nkReturnStmt, asgn) let retStmt = newTree(nkReturnStmt, asgn)
let branch = newTree(nkElifBranch, cmp, retStmt) let branch = newTree(nkElifBranch, cmp, retStmt)
# The C++ backend requires `getCurrentException` here. let nullifyExc = newTree(nkCall, newSymNode(ctx.g.getCompilerProc("closureIterSetupExc")), nilnode)
let raiseStmt = newTree(nkRaiseStmt, ctx.g.callCodegenProc("getCurrentException")) nullifyExc.info = info
let raiseStmt = newTree(nkRaiseStmt, curExc)
raiseStmt.info = info raiseStmt.info = info
let elseBranch = newTree(nkElse, raiseStmt) let elseBranch = newTree(nkElse, newTree(nkStmtList, nullifyExc, raiseStmt))
let ifBody = newTree(nkIfStmt, branch, elseBranch) let ifBody = newTree(nkIfStmt, branch, elseBranch)
let elifBranch = newTree(nkElifBranch, ctx.newUnrollFinallyAccess(info), ifBody) let elifBranch = newTree(nkElifBranch, ctx.newUnrollFinallyAccess(info), ifBody)

View file

@ -136,7 +136,6 @@ proc popCurrentExceptionEx(id: uint) {.compilerRtl.} =
prev.up = cur.up prev.up = cur.up
proc closureIterSetupExc(e: ref Exception) {.compilerproc, inline.} = proc closureIterSetupExc(e: ref Exception) {.compilerproc, inline.} =
if not e.isNil:
currException = e currException = e
# some platforms have native support for stack traces: # some platforms have native support for stack traces: