error on user pragma args (#21776)

closes #20978
This commit is contained in:
metagn
2023-05-03 15:18:55 +03:00
committed by GitHub
parent f37ecbb994
commit 44736d26cd
2 changed files with 10 additions and 1 deletions

View File

@@ -826,7 +826,8 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int,
validPragmas: TSpecialWords,
comesFromPush, isStatement: bool): bool =
var it = n[i]
var key = if it.kind in nkPragmaCallKinds and it.len > 1: it[0] else: it
let keyDeep = it.kind in nkPragmaCallKinds and it.len > 1
var key = if keyDeep: it[0] else: it
if key.kind == nkBracketExpr:
processNote(c, it)
return
@@ -852,6 +853,9 @@ 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)
if keyDeep:
localError(c.config, it.info, "user pragma cannot have arguments")
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

View File

@@ -0,0 +1,5 @@
var foo {.exportc: "abc".} = 123
{.pragma: importc2, importc.}
var bar {.importc2: "abc".}: int #[tt.Error
^ user pragma cannot have arguments]#
echo bar