From 6f13184e40b21956f53e407888ac2730a5e5e58c Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 25 Aug 2018 07:56:05 +0200 Subject: More checks for custom pragmas placement (#8765) We're not interested in custom pragmas attached to certain node kinds so the compiler silently ignored them. --- compiler/pragmas.nim | 9 ++++++--- tests/pragmas/t8741.nim | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 66682650d..c0de1edca 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -96,7 +96,9 @@ const errIntLiteralExpected = "integer literal expected" proc invalidPragma*(c: PContext; n: PNode) = - localError(c.config, n.info, "invalid pragma: " % renderTree(n, {renderNoComments})) + localError(c.config, n.info, "invalid pragma: " & renderTree(n, {renderNoComments})) +proc illegalCustomPragma*(c: PContext, n: PNode, s: PSym) = + localError(c.config, n.info, "cannot attach a custom pragma to '" & s.name.s & "'") proc pragmaAsm*(c: PContext, n: PNode): char = result = '\0' @@ -1094,9 +1096,10 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, else: sym.flags.incl sfUsed of wLiftLocals: discard else: invalidPragma(c, it) - else: + elif sym.kind in {skField,skProc,skFunc,skConverter,skMethod,skType}: n.sons[i] = semCustomPragma(c, it) - + else: + illegalCustomPragma(c, it, sym) proc implicitPragmas*(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords) = diff --git a/tests/pragmas/t8741.nim b/tests/pragmas/t8741.nim index 7398b1030..41f2f9e8a 100644 --- a/tests/pragmas/t8741.nim +++ b/tests/pragmas/t8741.nim @@ -1,6 +1,6 @@ discard """ line: 9 - errormsg: "attempting to call undeclared routine: 'foobar'" + errormsg: "cannot attach a custom pragma to 'a'" """ for a {.gensym, inject.} in @[1,2,3]: -- cgit 1.4.1-2-gfad0