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:
parent
0dc4d6dcc2
commit
3402926372
2 changed files with 14 additions and 2 deletions
|
|
@ -1288,7 +1288,11 @@ proc customPragmaNode(n: NimNode): NimNode =
|
||||||
typ = n.getTypeInst()
|
typ = n.getTypeInst()
|
||||||
|
|
||||||
if typ.typeKind == ntyTypeDesc:
|
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
|
if n.kind == nnkSym: # either an variable or a proc
|
||||||
let impl = n.getImpl()
|
let impl = n.getImpl()
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,9 @@ block: # A bit more advanced case
|
||||||
|
|
||||||
static: assert(hasCustomPragma(myproc, alternativeKey))
|
static: assert(hasCustomPragma(myproc, alternativeKey))
|
||||||
|
|
||||||
|
const hasFieldCustomPragma = s.field.hasCustomPragma(defaultValue)
|
||||||
|
static: assert(hasFieldCustomPragma == false)
|
||||||
|
|
||||||
# pragma on an object
|
# pragma on an object
|
||||||
static:
|
static:
|
||||||
assert Subfield.hasCustomPragma(defaultValue)
|
assert Subfield.hasCustomPragma(defaultValue)
|
||||||
|
|
@ -71,6 +74,8 @@ block: # ref types
|
||||||
MyFile {.defaultValue: "closed".} = ref object
|
MyFile {.defaultValue: "closed".} = ref object
|
||||||
path {.defaultValue: "invalid".}: string
|
path {.defaultValue: "invalid".}: string
|
||||||
|
|
||||||
|
TypeWithoutPragma = object
|
||||||
|
|
||||||
var s = NodeRef()
|
var s = NodeRef()
|
||||||
|
|
||||||
const
|
const
|
||||||
|
|
@ -91,7 +96,7 @@ block: # ref types
|
||||||
|
|
||||||
var ptrS = NodePtr(nil)
|
var ptrS = NodePtr(nil)
|
||||||
const
|
const
|
||||||
ptrRightSerKey = getCustomPragmaVal(s.right, serializationKey)
|
ptrRightSerKey = getCustomPragmaVal(ptrS.right, serializationKey)
|
||||||
static:
|
static:
|
||||||
assert ptrRightSerKey == "r"
|
assert ptrRightSerKey == "r"
|
||||||
|
|
||||||
|
|
@ -103,6 +108,9 @@ block: # ref types
|
||||||
assert fileDefVal == "closed"
|
assert fileDefVal == "closed"
|
||||||
assert filePathDefVal == "invalid"
|
assert filePathDefVal == "invalid"
|
||||||
|
|
||||||
|
static:
|
||||||
|
assert TypeWithoutPragma.hasCustomPragma(defaultValue) == false
|
||||||
|
|
||||||
block:
|
block:
|
||||||
type
|
type
|
||||||
VariantKind = enum
|
VariantKind = enum
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue