summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorYuriy Glukhov <yglukhov@users.noreply.github.com>2019-09-10 08:54:51 +0300
committerAndreas Rumpf <rumpf_a@web.de>2019-09-10 07:54:51 +0200
commit5d9c1544bf8cb66e479e9816987f2241645b3568 (patch)
tree6656e7d61c6f6e46f0ba29b8fdfecaca5b6108ba
parent60911304b4148545391eaa3003aceb9677283fa1 (diff)
downloadNim-5d9c1544bf8cb66e479e9816987f2241645b3568.tar.gz
Allow ProcTy in addPragma and friends (#12158)
-rw-r--r--lib/core/macros.nim18
1 files changed, 12 insertions, 6 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim
index 4e44b9b4f..2e1eeb042 100644
--- a/lib/core/macros.nim
+++ b/lib/core/macros.nim
@@ -1191,17 +1191,23 @@ proc `params=`* (someProc: NimNode; params: NimNode) {.compileTime.}=
 proc pragma*(someProc: NimNode): NimNode {.compileTime.} =
   ## Get the pragma of a proc type
   ## These will be expanded
-  someProc.expectRoutine
-  result = someProc[4]
-proc `pragma=`*(someProc: NimNode; val: NimNode){.compileTime.}=
+  if someProc.kind == nnkProcTy:
+    result = someProc[1]
+  else:
+    someProc.expectRoutine
+    result = someProc[4]
+proc `pragma=`*(someProc: NimNode; val: NimNode) {.compileTime.}=
   ## Set the pragma of a proc type
-  someProc.expectRoutine
   expectKind(val, {nnkEmpty, nnkPragma})
-  someProc[4] = val
+  if someProc.kind == nnkProcTy:
+    someProc[1] = val
+  else:
+    someProc.expectRoutine
+    someProc[4] = val
 
 proc addPragma*(someProc, pragma: NimNode) {.compileTime.} =
   ## Adds pragma to routine definition
-  someProc.expectRoutine
+  someProc.expectKind(RoutineNodes + {nnkProcTy})
   var pragmaNode = someProc.pragma
   if pragmaNode.isNil or pragmaNode.kind == nnkEmpty:
     pragmaNode = newNimNode(nnkPragma)