Skip to content

Commit 96a02f1

Browse files
ringaboutnarimiran
authored andcommitted
fixes #23355; pop optionStack when exiting scopes (#24926)
fixes #23355 (cherry picked from commit 98ec87d)
1 parent c1fbde1 commit 96a02f1

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

compiler/ast.nim

Lines changed: 1 addition & 0 deletions
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

Lines changed: 4 additions & 1 deletion
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

Lines changed: 11 additions & 0 deletions
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)