mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-13 06:43:52 +00:00
macros: make hasCustomPragma more permissive (#19747)
Make hasCustomPragma return false rather than fail for invalid
parameters.
(cherry picked from commit 82680a12a7)
This commit is contained in:
@@ -1538,7 +1538,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()
|
||||
|
||||
@@ -1549,7 +1549,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
|
||||
@@ -1577,7 +1579,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])
|
||||
|
||||
Reference in New Issue
Block a user