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.
This commit is contained in:
LemonBoy 2018-08-25 07:56:05 +02:00 • committed by Andreas Rumpf
commit 6f13184e40
2 changed files with 7 additions and 4 deletions

View file

@ -96,7 +96,9 @@ const
errIntLiteralExpected = "integer literal expected" errIntLiteralExpected = "integer literal expected"
proc invalidPragma*(c: PContext; n: PNode) = 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 = proc pragmaAsm*(c: PContext, n: PNode): char =
result = '\0' result = '\0'
@ -1094,9 +1096,10 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
else: sym.flags.incl sfUsed else: sym.flags.incl sfUsed
of wLiftLocals: discard of wLiftLocals: discard
else: invalidPragma(c, it) else: invalidPragma(c, it)
else: elif sym.kind in {skField,skProc,skFunc,skConverter,skMethod,skType}:
n.sons[i] = semCustomPragma(c, it) n.sons[i] = semCustomPragma(c, it)
else:
illegalCustomPragma(c, it, sym)
proc implicitPragmas*(c: PContext, sym: PSym, n: PNode, proc implicitPragmas*(c: PContext, sym: PSym, n: PNode,
validPragmas: TSpecialWords) = validPragmas: TSpecialWords) =

View file

@ -1,6 +1,6 @@
discard """ discard """
line: 9 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]: for a {.gensym, inject.} in @[1,2,3]: