fix infinite recursion with pushed user pragmas (#24839)

fixes #24838

(cherry picked from commit 5bcd9a329a)
This commit is contained in:
metagn
2025-04-03 13:53:42 +03:00
committed by narimiran
parent 31effe8c75
commit 23ca21a9c4
2 changed files with 20 additions and 4 deletions

View File

@@ -107,7 +107,7 @@ proc getPragmaVal*(procAst: PNode; name: TSpecialWord): PNode =
return it[1]
proc pragma*(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords;
isStatement: bool = false)
isStatement: bool = false; comesFromPush = false)
proc recordPragma(c: PContext; n: PNode; args: varargs[string]) =
var recorded = newNodeI(nkReplayAction, n.info)
@@ -893,7 +893,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
if keyDeep:
localError(c.config, it.info, "user pragma cannot have arguments")
pragma(c, sym, userPragma.ast, validPragmas, isStatement)
pragma(c, sym, userPragma.ast, validPragmas, isStatement, comesFromPush)
n.sons[i..i] = userPragma.ast.sons # expand user pragma with its content
i.inc(userPragma.ast.len - 1) # inc by -1 is ok, user pragmas was empty
else:
@@ -1405,11 +1405,12 @@ proc pragmaRec(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords;
inc i
proc pragma(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords;
isStatement: bool) =
isStatement: bool; comesFromPush = false) =
if n == nil: return
pragmaRec(c, sym, n, validPragmas, isStatement)
# XXX: in the case of a callable def, this should use its info
implicitPragmas(c, sym, n.info, validPragmas)
if not comesFromPush:
implicitPragmas(c, sym, n.info, validPragmas)
proc pragmaCallable*(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords,
isStatement: bool = false) =

View File

@@ -0,0 +1,15 @@
# issue #24838
{.pragma: testit, raises: [], deprecated: "abc".}
{.push testit.}
proc xxx() {.testit.} =
discard "hello"
proc yyy() =
discard "hello"
{.pop.}
xxx() #[tt.Warning
^ abc; xxx is deprecated [Deprecated]]#
yyy() #[tt.Warning
^ abc; yyy is deprecated [Deprecated]]#