summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorTanguy <tanguy@status.im>2022-09-16 20:10:47 +0200
committerGitHub <noreply@github.com>2022-09-17 02:10:47 +0800
commit3a5e38ab9dd560ae8e29e66980b1cc4bbf45ebaf (patch)
treebb607e5dff0ded0f57d1100d33ff69404ba8dcd5
parentd44b547144e2db5ec7083219a77b318d4dff0133 (diff)
downloadNim-3a5e38ab9dd560ae8e29e66980b1cc4bbf45ebaf.tar.gz
Allow custom pragma on iterators [backport] (#20344)
Allow custom pragma on iterators
-rw-r--r--compiler/pragmas.nim2
-rw-r--r--tests/pragmas/tcustom_pragma.nim7
2 files changed, 8 insertions, 1 deletions
diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim
index 06e861084..101b17bf6 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 db2536188..b624f32ba 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.}