diff options
author | LemonBoy <LemonBoy@users.noreply.github.com> | 2018-08-23 21:43:10 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-08-23 21:43:10 +0200 |
commit | 25f5ea7000a4ae24a45d138307e62c0015d3c4df (patch) | |
tree | becaed9588363c41dd3acee9ac55b29b6502e1ca | |
parent | 35e37fd8ec721f8588b88fd72c16e36916573908 (diff) | |
download | Nim-25f5ea7000a4ae24a45d138307e62c0015d3c4df.tar.gz |
Validate pragmas attached to for variables (#8749)
Fixes #8741
-rw-r--r-- | compiler/pragmas.nim | 1 | ||||
-rw-r--r-- | compiler/semstmts.nim | 2 | ||||
-rw-r--r-- | tests/pragmas/t8741.nim | 10 |
3 files changed, 13 insertions, 0 deletions
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 |