mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-04 02:44:44 +00:00
hasCustomPragma/getCustomPragmaVal: small fix (#7650)
* fix hasCustomPragma/getCustomPragmaVal for types without pragma * fix pragma on pointer test * removed trailing spaces
This commit is contained in:
@@ -1288,7 +1288,11 @@ proc customPragmaNode(n: NimNode): NimNode =
|
||||
typ = n.getTypeInst()
|
||||
|
||||
if typ.typeKind == ntyTypeDesc:
|
||||
return typ[1].getImpl()[0][1]
|
||||
let impl = typ[1].getImpl()
|
||||
if impl[0].kind == nnkPragmaExpr:
|
||||
return impl[0][1]
|
||||
else:
|
||||
return impl[0] # handle types which don't have macro at all
|
||||
|
||||
if n.kind == nnkSym: # either an variable or a proc
|
||||
let impl = n.getImpl()
|
||||
|
||||
@@ -51,6 +51,9 @@ block: # A bit more advanced case
|
||||
|
||||
static: assert(hasCustomPragma(myproc, alternativeKey))
|
||||
|
||||
const hasFieldCustomPragma = s.field.hasCustomPragma(defaultValue)
|
||||
static: assert(hasFieldCustomPragma == false)
|
||||
|
||||
# pragma on an object
|
||||
static:
|
||||
assert Subfield.hasCustomPragma(defaultValue)
|
||||
@@ -71,6 +74,8 @@ block: # ref types
|
||||
MyFile {.defaultValue: "closed".} = ref object
|
||||
path {.defaultValue: "invalid".}: string
|
||||
|
||||
TypeWithoutPragma = object
|
||||
|
||||
var s = NodeRef()
|
||||
|
||||
const
|
||||
@@ -91,7 +96,7 @@ block: # ref types
|
||||
|
||||
var ptrS = NodePtr(nil)
|
||||
const
|
||||
ptrRightSerKey = getCustomPragmaVal(s.right, serializationKey)
|
||||
ptrRightSerKey = getCustomPragmaVal(ptrS.right, serializationKey)
|
||||
static:
|
||||
assert ptrRightSerKey == "r"
|
||||
|
||||
@@ -103,6 +108,9 @@ block: # ref types
|
||||
assert fileDefVal == "closed"
|
||||
assert filePathDefVal == "invalid"
|
||||
|
||||
static:
|
||||
assert TypeWithoutPragma.hasCustomPragma(defaultValue) == false
|
||||
|
||||
block:
|
||||
type
|
||||
VariantKind = enum
|
||||
|
||||
Reference in New Issue
Block a user