From 3a5e38ab9dd560ae8e29e66980b1cc4bbf45ebaf Mon Sep 17 00:00:00 2001 From: Tanguy Date: Fri, 16 Sep 2022 20:10:47 +0200 Subject: [PATCH] Allow custom pragma on iterators [backport] (#20344) Allow custom pragma on iterators --- compiler/pragmas.nim | 2 +- tests/pragmas/tcustom_pragma.nim | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 06e8610841d25..101b17bf628d3 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -1247,7 +1247,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, elif comesFromPush and whichKeyword(ident) != wInvalid: discard "ignore the .push pragma; it doesn't apply" else: - if sym == nil or (sym.kind in {skVar, skLet, skParam, + if sym == nil or (sym.kind in {skVar, skLet, skParam, skIterator, skField, skProc, skFunc, skConverter, skMethod, skType}): n[i] = semCustomPragma(c, it) elif sym != nil: diff --git a/tests/pragmas/tcustom_pragma.nim b/tests/pragmas/tcustom_pragma.nim index db25361889dd4..b624f32ba32b7 100644 --- a/tests/pragmas/tcustom_pragma.nim +++ b/tests/pragmas/tcustom_pragma.nim @@ -399,6 +399,13 @@ block: discard Hello(a: 1.0, b: 12) +# custom pragma on iterators +block: + template prag {.pragma.} + {.push prag.} + proc hello = discard + iterator hello2: int = discard + # issue #11511 when false: template myAttr {.pragma.}