summary refs log tree commit diff stats
diff options
context:
space:
mode:
authormetagn <metagngn@gmail.com>2024-09-22 14:56:40 +0300
committerGitHub <noreply@github.com>2024-09-22 13:56:40 +0200
commit7da2ffb7513192ccfd29f62eed613298b3a6f6f4 (patch)
treef8cb79b1af4400eb89ce722860645ef31e780d2d
parent5c843d3d60982bb0669107ee67863737f52574ba (diff)
downloadNim-7da2ffb7513192ccfd29f62eed613298b3a6f6f4.tar.gz
fix custom pragma with backticks not working [backport] (#24151)
refs https://forum.nim-lang.org/t/12522
-rw-r--r--compiler/pragmas.nim7
-rw-r--r--tests/pragmas/tcustom_pragma.nim7
2 files changed, 11 insertions, 3 deletions
diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim
index 78b6728d5..c4be1223b 100644
--- a/compiler/pragmas.nim
+++ b/compiler/pragmas.nim
@@ -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)
diff --git a/tests/pragmas/tcustom_pragma.nim b/tests/pragmas/tcustom_pragma.nim
index 9ffa9a33d..11a6df813 100644
--- a/tests/pragmas/tcustom_pragma.nim
+++ b/tests/pragmas/tcustom_pragma.nim
@@ -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)