mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-17 16:38:33 +00:00
fix infinite recursion with pushed user pragmas (#24839)
fixes #24838
(cherry picked from commit 5bcd9a329a)
This commit is contained in:
@@ -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) =
|
||||
|
||||
15
tests/pragmas/tpushuserpragma.nim
Normal file
15
tests/pragmas/tpushuserpragma.nim
Normal 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]]#
|
||||
Reference in New Issue
Block a user