Skip to content

Commit

Permalink
fix custom pragma with backticks not working [backport] (#24151)
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn authored Sep 22, 2024
1 parent 5c843d3 commit 7da2ffb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 4 additions & 3 deletions compiler/pragmas.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions tests/pragmas/tcustom_pragma.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 7da2ffb

Please sign in to comment.