From 08159733cd1ab508a611cf60380572e879ae7f0f Mon Sep 17 00:00:00 2001 From: Clyybber Date: Wed, 15 Jul 2020 11:34:10 +0200 Subject: [PATCH] Fix #14985 (#14988) --- compiler/injectdestructors.nim | 4 ++-- tests/arc/tmovebug.nim | 30 ++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index ff311f079..98cfb4743 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -660,7 +660,7 @@ template handleNestedTempl(n, processCall: untyped, willProduceStmt = false) = branch[0] = p(it[0], c, s, normal) branch[^1] = if it[^1].typ.isEmptyType or willProduceStmt: - processScope(c, branchScope, processCall(it[^1], branchScope)) + processScope(c, branchScope, maybeVoid(it[^1], branchScope)) else: processScopeExpr(c, branchScope, it[^1], processCall) result.add branch @@ -679,7 +679,7 @@ template handleNestedTempl(n, processCall: untyped, willProduceStmt = false) = var branchScope = nestedScope(s) branch[^1] = if it[^1].typ.isEmptyType or willProduceStmt or it.kind == nkFinally: processScope(c, branchScope, if it.kind == nkFinally: p(it[^1], c, branchScope, normal) - else: processCall(it[^1], branchScope)) + else: maybeVoid(it[^1], branchScope)) else: processScopeExpr(c, branchScope, it[^1], processCall) result.add branch diff --git a/tests/arc/tmovebug.nim b/tests/arc/tmovebug.nim index 424785ed7..3b7a7c5df 100644 --- a/tests/arc/tmovebug.nim +++ b/tests/arc/tmovebug.nim @@ -67,6 +67,9 @@ ho king live long; long live king +hi +try +bye ''' """ @@ -494,3 +497,30 @@ proc weirdScopes = echo king weirdScopes() + + +# bug #14985 +proc getScope(): string = + if true: + return "hi" + else: + "else" + +echo getScope() + +proc getScope3(): string = + try: + "try" + except: + return "except" + +echo getScope3() + +proc getScope2(): string = + case true + of true: + return "bye" + else: + "else" + +echo getScope2()