Skip to content

Commit 5bcd9a3

Browse files
authored
fix infinite recursion with pushed user pragmas (#24839)
fixes #24838
1 parent 4352fa2 commit 5bcd9a3

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

compiler/pragmas.nim

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ proc getPragmaVal*(procAst: PNode; name: TSpecialWord): PNode =
107107
return it[1]
108108

109109
proc pragma*(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords;
110-
isStatement: bool = false)
110+
isStatement: bool = false; comesFromPush = false)
111111

112112
proc recordPragma(c: PContext; n: PNode; args: varargs[string]) =
113113
var recorded = newNodeI(nkReplayAction, n.info)
@@ -893,7 +893,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
893893
if keyDeep:
894894
localError(c.config, it.info, "user pragma cannot have arguments")
895895

896-
pragma(c, sym, userPragma.ast, validPragmas, isStatement)
896+
pragma(c, sym, userPragma.ast, validPragmas, isStatement, comesFromPush)
897897
n.sons[i..i] = userPragma.ast.sons # expand user pragma with its content
898898
i.inc(userPragma.ast.len - 1) # inc by -1 is ok, user pragmas was empty
899899
else:
@@ -1405,11 +1405,12 @@ proc pragmaRec(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords;
14051405
inc i
14061406

14071407
proc pragma(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords;
1408-
isStatement: bool) =
1408+
isStatement: bool; comesFromPush = false) =
14091409
if n == nil: return
14101410
pragmaRec(c, sym, n, validPragmas, isStatement)
14111411
# XXX: in the case of a callable def, this should use its info
1412-
implicitPragmas(c, sym, n.info, validPragmas)
1412+
if not comesFromPush:
1413+
implicitPragmas(c, sym, n.info, validPragmas)
14131414

14141415
proc pragmaCallable*(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords,
14151416
isStatement: bool = false) =

tests/pragmas/tpushuserpragma.nim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# issue #24838
2+
3+
{.pragma: testit, raises: [], deprecated: "abc".}
4+
5+
{.push testit.}
6+
proc xxx() {.testit.} =
7+
discard "hello"
8+
proc yyy() =
9+
discard "hello"
10+
{.pop.}
11+
12+
xxx() #[tt.Warning
13+
^ abc; xxx is deprecated [Deprecated]]#
14+
yyy() #[tt.Warning
15+
^ abc; yyy is deprecated [Deprecated]]#

0 commit comments

Comments
 (0)