From 25f5ea7000a4ae24a45d138307e62c0015d3c4df Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Thu, 23 Aug 2018 21:43:10 +0200 Subject: Validate pragmas attached to for variables (#8749) Fixes #8741 --- compiler/pragmas.nim | 1 + compiler/semstmts.nim | 2 ++ tests/pragmas/t8741.nim | 10 ++++++++++ 3 files changed, 13 insertions(+) create mode 100644 tests/pragmas/t8741.nim diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 263068344..66682650d 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -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 = diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 6cf2e2d96..425bb24dc 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -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 diff --git a/tests/pragmas/t8741.nim b/tests/pragmas/t8741.nim new file mode 100644 index 000000000..7398b1030 --- /dev/null +++ b/tests/pragmas/t8741.nim @@ -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 -- cgit 1.4.1-2-gfad0