diff --git a/compiler/ast.nim b/compiler/ast.nim index e35a0b2031..3d7dcbdfc7 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -684,6 +684,7 @@ type symbols*: TStrTable parent*: PScope allowPrivateAccess*: seq[PSym] # # enable access to private fields + optionStackLen*: int PScope* = ref TScope diff --git a/compiler/lookups.nim b/compiler/lookups.nim index ec5fdd69b0..34f65973cf 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -75,10 +75,13 @@ proc addUniqueSym*(scope: PScope, s: PSym): PSym = proc openScope*(c: PContext): PScope {.discardable.} = result = PScope(parent: c.currentScope, symbols: initStrTable(), - depthLevel: c.scopeDepth + 1) + depthLevel: c.scopeDepth + 1, + optionStackLen: c.optionStack.len) c.currentScope = result proc rawCloseScope*(c: PContext) = + if c.currentScope.optionStackLen >= 1: + c.optionStack.setLen(c.currentScope.optionStackLen) c.currentScope = c.currentScope.parent proc closeScope*(c: PContext) = diff --git a/tests/errmsgs/t23355.nim b/tests/errmsgs/t23355.nim new file mode 100644 index 0000000000..281d098eb8 --- /dev/null +++ b/tests/errmsgs/t23355.nim @@ -0,0 +1,11 @@ +discard """ + errormsg: "{.pop.} without a corresponding {.push.}" +""" + +block: + {.push raises: [].} + +proc f() = + {.pop.} + +proc g() = raise newException(ValueError, "") \ No newline at end of file