diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2019-09-11 18:35:13 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-11 18:35:13 +0200 |
commit | 560eef5bbe1820914e94d3252a2d86fbc91ccd00 (patch) | |
tree | c689647ff313b33f054a2146073a8c8e3cf5ed23 /compiler | |
parent | 33b8a00aa837009a4ad27a7ce5cb52ce06afafa0 (diff) | |
download | Nim-560eef5bbe1820914e94d3252a2d86fbc91ccd00.tar.gz |
fixes #12171 (#12173)
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/pragmas.nim | 22 | ||||
-rw-r--r-- | compiler/semexprs.nim | 2 |
2 files changed, 14 insertions, 10 deletions
diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index e7517b6da..e9a89bc44 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -85,7 +85,8 @@ proc getPragmaVal*(procAst: PNode; name: TSpecialWord): PNode = it[0].ident.id == ord(name): return it[1] -proc pragma*(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords) +proc pragma*(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords; + isStatement: bool = false) proc recordPragma(c: PContext; n: PNode; key, val: string; val2 = "") = var recorded = newNodeI(nkCommentStmt, n.info) @@ -747,7 +748,8 @@ proc semCustomPragma(c: PContext, n: PNode): PNode = result.kind = n.kind proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, - validPragmas: TSpecialWords, comesFromPush: bool) : bool = + validPragmas: TSpecialWords, + comesFromPush, isStatement: bool) : bool = var it = n.sons[i] var key = if it.kind in nkPragmaCallKinds and it.len > 1: it.sons[0] else: it if key.kind == nkBracketExpr: @@ -767,7 +769,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, if c.instCounter > 100: globalError(c.config, it.info, "recursive dependency: " & userPragma.name.s) - pragma(c, sym, userPragma.ast, validPragmas) + pragma(c, sym, userPragma.ast, validPragmas, isStatement) n.sons[i..i] = userPragma.ast.sons # expand user pragma with its content i.inc(userPragma.ast.len - 1) # inc by -1 is ok, user pragmas was empty dec c.instCounter @@ -969,7 +971,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, recordPragma(c, it, "warning", s) message(c.config, it.info, warnUser, s) of wError: - if sym != nil and (sym.isRoutine or sym.kind == skType) and wUsed in validPragmas: + if sym != nil and (sym.isRoutine or sym.kind == skType) and not isStatement: # This is subtle but correct: the error *statement* is only # allowed when 'wUsed' is not in validPragmas. Here this is the easiest way to # distinguish properly between @@ -1168,7 +1170,7 @@ proc implicitPragmas*(c: PContext, sym: PSym, n: PNode, pushInfoContext(c.config, n.info) var i = 0 while i < o.len: - if singlePragma(c, sym, o, i, validPragmas, true): + if singlePragma(c, sym, o, i, validPragmas, true, false): internalError(c.config, n.info, "implicitPragmas") inc i popInfoContext(c.config) @@ -1193,14 +1195,16 @@ proc hasPragma*(n: PNode, pragma: TSpecialWord): bool = return false -proc pragmaRec(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords) = +proc pragmaRec(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords; + isStatement: bool) = if n == nil: return var i = 0 while i < n.len: - if singlePragma(c, sym, n, i, validPragmas, false): break + if singlePragma(c, sym, n, i, validPragmas, false, isStatement): break inc i -proc pragma(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords) = +proc pragma(c: PContext, sym: PSym, n: PNode, validPragmas: TSpecialWords; + isStatement: bool) = if n == nil: return - pragmaRec(c, sym, n, validPragmas) + pragmaRec(c, sym, n, validPragmas, isStatement) implicitPragmas(c, sym, n, validPragmas) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index bae660805..eb5b8d2c1 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -2748,7 +2748,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = of nkUsingStmt: result = semUsing(c, n) of nkAsmStmt: result = semAsm(c, n) of nkYieldStmt: result = semYield(c, n) - of nkPragma: pragma(c, c.p.owner, n, stmtPragmas) + of nkPragma: pragma(c, c.p.owner, n, stmtPragmas, true) of nkIteratorDef: result = semIterator(c, n) of nkProcDef: result = semProc(c, n) of nkFuncDef: result = semFunc(c, n) |