diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/pragmas.nim | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index e51eb054b..2efef6fee 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -116,7 +116,15 @@ const proc invalidPragma*(c: PContext; n: PNode) = 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 & "'") + var msg = "cannot attach a custom pragma to '" & s.name.s & "'" + if s != nil: + msg.add("; custom pragmas are not supported for ") + case s.kind + of skForVar: msg.add("`for` loop variables") + of skEnumField: msg.add("enum fields") + of skModule: msg.add("modules") + else: msg.add("symbol kind " & $s.kind) + localError(c.config, n.info, msg) proc pragmaProposition(c: PContext, n: PNode) = if n.kind notin nkPragmaCallKinds or n.len != 2: @@ -755,7 +763,7 @@ proc pragmaGuard(c: PContext; it: PNode; kind: TSymKind): PSym = else: result = qualifiedLookUp(c, n, {checkUndeclared}) -proc semCustomPragma(c: PContext, n: PNode): PNode = +proc semCustomPragma(c: PContext, n: PNode, sym: PSym): PNode = var callNode: PNode if n.kind in {nkIdent, nkSym}: @@ -774,6 +782,11 @@ proc semCustomPragma(c: PContext, n: PNode): PNode = if r.isNil or sfCustomPragma notin r[0].sym.flags: invalidPragma(c, n) return n + + # we have a valid custom pragma + if sym != nil and sym.kind in {skEnumField, skForVar, skModule}: + illegalCustomPragma(c, n, sym) + return n result = r # Transform the nkCall node back to its original form if possible @@ -822,7 +835,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, else: discard return elif key.kind notin nkIdentKinds: - n[i] = semCustomPragma(c, it) + n[i] = semCustomPragma(c, it, sym) return let ident = considerQuotedIdent(c, key) var userPragma = strTableGet(c.userPragmas, ident) @@ -1248,13 +1261,8 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, elif comesFromPush and whichKeyword(ident) != wInvalid: discard "ignore the .push pragma; it doesn't apply" else: - if sym == nil or (sym.kind in {skVar, skLet, skConst, skParam, skIterator, - skField, skProc, skFunc, skConverter, skMethod, skType}): - n[i] = semCustomPragma(c, it) - elif sym != nil: - illegalCustomPragma(c, it, sym) - else: - invalidPragma(c, it) + # semCustomPragma gives appropriate error for invalid pragmas + n[i] = semCustomPragma(c, it, sym) proc overwriteLineInfo(n: PNode; info: TLineInfo) = n.info = info |