diff --git a/compiler/ast.nim b/compiler/ast.nim index b0a8ee6398..afcc6f8ab2 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -1258,8 +1258,11 @@ proc getDeclPragma*(n: PNode): PNode = proc extractPragma*(s: PSym): PNode = ## gets the pragma node of routine/type/var/let/const symbol `s` - if s.kind in routineKinds: - result = s.ast[pragmasPos] + if s.kind in routineKinds: # bug #24167 + if s.ast[pragmasPos] != nil and s.ast[pragmasPos].kind != nkEmpty: + result = s.ast[pragmasPos] + else: + result = nil elif s.kind in {skType, skVar, skLet, skConst}: if s.ast != nil and s.ast.len > 0: if s.ast[0].kind == nkPragmaExpr and s.ast[0].len > 1: diff --git a/tests/pragmas/tpush.nim b/tests/pragmas/tpush.nim index 404cd0ab4e..c09988e2f9 100644 --- a/tests/pragmas/tpush.nim +++ b/tests/pragmas/tpush.nim @@ -64,3 +64,9 @@ foo31() foo41() {.pop.} + +block: + {.push deprecated.} + template test() = discard + test() + {.pop.}