Skip to content

Commit

Permalink
Validate pragmas attached to for variables (#8749)
Browse files Browse the repository at this point in the history
Fixes #8741
  • Loading branch information
LemonBoy authored and Araq committed Aug 23, 2018
1 parent 35e37fd commit 25f5ea7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/pragmas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const
letPragmas* = varPragmas
procTypePragmas* = {FirstCallConv..LastCallConv, wVarargs, wNosideeffect,
wThread, wRaises, wLocks, wTags, wGcSafe}
forVarPragmas* = {wInject, wGensym}
allRoutinePragmas* = methodPragmas + iteratorPragmas + lambdaPragmas

proc getPragmaVal*(procAst: PNode; name: TSpecialWord): PNode =
Expand Down
2 changes: 2 additions & 0 deletions compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,8 @@ proc symForVar(c: PContext, n: PNode): PSym =
let m = if n.kind == nkPragmaExpr: n.sons[0] else: n
result = newSymG(skForVar, m, c)
styleCheckDef(c.config, result)
if n.kind == nkPragmaExpr:
pragma(c, result, n.sons[1], forVarPragmas)

proc semForVars(c: PContext, n: PNode): PNode =
result = n
Expand Down
10 changes: 10 additions & 0 deletions tests/pragmas/t8741.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
discard """
line: 9
errormsg: "attempting to call undeclared routine: 'foobar'"
"""

for a {.gensym, inject.} in @[1,2,3]:
discard

for a {.foobar.} in @[1,2,3]:
discard

0 comments on commit 25f5ea7

Please sign in to comment.