fix custom pragma with backticks not working [backport] (#24151)

refs https://forum.nim-lang.org/t/12522
This commit is contained in:
metagn
2024-09-22 14:56:40 +03:00
committed by GitHub
parent 5c843d3d60
commit 7da2ffb751
2 changed files with 11 additions and 3 deletions

View File

@@ -800,13 +800,14 @@ proc pragmaGuard(c: PContext; it: PNode; kind: TSymKind): PSym =
proc semCustomPragma(c: PContext, n: PNode, sym: PSym): PNode =
var callNode: PNode
if n.kind in {nkIdent, nkSym}:
case n.kind
of nkIdentKinds:
# pragma -> pragma()
callNode = newTree(nkCall, n)
elif n.kind == nkExprColonExpr:
of nkExprColonExpr:
# pragma: arg -> pragma(arg)
callNode = newTree(nkCall, n[0], n[1])
elif n.kind in nkPragmaCallKinds:
of nkPragmaCallKinds - {nkExprColonExpr}:
callNode = n
else:
invalidPragma(c, n)

View File

@@ -531,3 +531,10 @@ block:
check(a)
check(b)
block: # https://forum.nim-lang.org/t/12522, backticks
template `mypragma`() {.pragma.}
# Error: invalid pragma: `mypragma`
type Test = object
field {.`mypragma`.}: int
doAssert Test().field.hasCustomPragma(mypragma)