Skip to content

Commit cba0c20

Browse files
Menduistnarimiran
authored andcommitted
Allow custom pragma on iterators [backport] (#20344)
Allow custom pragma on iterators (cherry picked from commit 3a5e38a)
1 parent 60f43fb commit cba0c20

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

compiler/pragmas.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
12421242
elif comesFromPush and whichKeyword(ident) != wInvalid:
12431243
discard "ignore the .push pragma; it doesn't apply"
12441244
else:
1245-
if sym == nil or (sym.kind in {skVar, skLet, skParam,
1245+
if sym == nil or (sym.kind in {skVar, skLet, skParam, skIterator,
12461246
skField, skProc, skFunc, skConverter, skMethod, skType}):
12471247
n[i] = semCustomPragma(c, it)
12481248
elif sym != nil:

tests/pragmas/tcustom_pragma.nim

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,13 @@ block:
383383

384384
discard Hello(a: 1.0, b: 12)
385385

386+
# custom pragma on iterators
387+
block:
388+
template prag {.pragma.}
389+
{.push prag.}
390+
proc hello = discard
391+
iterator hello2: int = discard
392+
386393
# issue #11511
387394
when false:
388395
template myAttr {.pragma.}

0 commit comments

Comments
 (0)