summary refs log tree commit diff stats
path: root/lib/core
diff options
context:
space:
mode:
authorehmry <ehmry@posteo.net>2022-04-25 15:16:11 -0500
committerGitHub <noreply@github.com>2022-04-25 22:16:11 +0200
commit82680a12a7a6acfbb6f5fdd22c042e409081b812 (patch)
tree2632054fd2c63209d13d51f6879228267978ff46 /lib/core
parent42ac50e988a4734624b204740613c795a0e789a3 (diff)
downloadNim-82680a12a7a6acfbb6f5fdd22c042e409081b812.tar.gz
macros: make hasCustomPragma more permissive (#19747)
Make hasCustomPragma return false rather than fail for invalid
parameters.
Diffstat (limited to 'lib/core')
-rw-r--r--lib/core/macros.nim8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/core/macros.nim b/lib/core/macros.nim
index ba19712cf..b370aaa7b 100644
--- a/lib/core/macros.nim
+++ b/lib/core/macros.nim
@@ -1521,7 +1521,7 @@ proc extractTypeImpl(n: NimNode): NimNode =
   else: error("Invalid node to retrieve type implementation of: " & $n.kind)
 
 proc customPragmaNode(n: NimNode): NimNode =
-  expectKind(n, {nnkSym, nnkDotExpr, nnkBracketExpr, nnkTypeOfExpr, nnkCheckedFieldExpr})
+  expectKind(n, {nnkSym, nnkDotExpr, nnkBracketExpr, nnkTypeOfExpr, nnkType, nnkCheckedFieldExpr})
   let
     typ = n.getTypeInst()
 
@@ -1532,7 +1532,9 @@ proc customPragmaNode(n: NimNode): NimNode =
       if kind(typ[1]) == nnkBracketExpr: typ[1][0]
       else: typ[1]
     )
-    if impl[0].kind == nnkPragmaExpr:
+    if impl.kind == nnkNilLit:
+      return impl
+    elif impl[0].kind == nnkPragmaExpr:
       return impl[0][1]
     else:
       return impl[0] # handle types which don't have macro at all
@@ -1560,7 +1562,7 @@ proc customPragmaNode(n: NimNode): NimNode =
     while typDef != nil:
       typDef.expectKind(nnkTypeDef)
       let typ = typDef[2].extractTypeImpl()
-      typ.expectKind({nnkRefTy, nnkPtrTy, nnkObjectTy})
+      if typ.kind notin {nnkRefTy, nnkPtrTy, nnkObjectTy}: break
       let isRef = typ.kind in {nnkRefTy, nnkPtrTy}
       if isRef and typ[0].kind in {nnkSym, nnkBracketExpr}: # defines ref type for another object(e.g. X = ref X)
         typDef = getImpl(typ[0])