Skip to content

Commit 98ec87d

Browse files
authored
fixes #23355; pop optionStack when exiting scopes (#24926)
fixes #23355
1 parent f56568d commit 98ec87d

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

compiler/ast.nim

+1
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,7 @@ type
684684
symbols*: TStrTable
685685
parent*: PScope
686686
allowPrivateAccess*: seq[PSym] # # enable access to private fields
687+
optionStackLen*: int
687688

688689
PScope* = ref TScope
689690

compiler/lookups.nim

+4-1
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,13 @@ proc addUniqueSym*(scope: PScope, s: PSym): PSym =
7575
proc openScope*(c: PContext): PScope {.discardable.} =
7676
result = PScope(parent: c.currentScope,
7777
symbols: initStrTable(),
78-
depthLevel: c.scopeDepth + 1)
78+
depthLevel: c.scopeDepth + 1,
79+
optionStackLen: c.optionStack.len)
7980
c.currentScope = result
8081

8182
proc rawCloseScope*(c: PContext) =
83+
if c.currentScope.optionStackLen >= 1:
84+
c.optionStack.setLen(c.currentScope.optionStackLen)
8285
c.currentScope = c.currentScope.parent
8386

8487
proc closeScope*(c: PContext) =

tests/errmsgs/t23355.nim

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
discard """
2+
errormsg: "{.pop.} without a corresponding {.push.}"
3+
"""
4+
5+
block:
6+
{.push raises: [].}
7+
8+
proc f() =
9+
{.pop.}
10+
11+
proc g() = raise newException(ValueError, "")

0 commit comments

Comments
 (0)