* fixes #8371, macros.hasCustomPragma doesn't crash anymore * fix macros.hasCustomPragma
This commit is contained in:
parent
060871e64a
commit
9c3336dcff
2 changed files with 23 additions and 1 deletions
|
|
@ -1284,7 +1284,7 @@ proc customPragmaNode(n: NimNode): NimNode =
|
||||||
let
|
let
|
||||||
typ = n.getTypeInst()
|
typ = n.getTypeInst()
|
||||||
|
|
||||||
if typ.kind == nnkBracketExpr and typ.len > 1 and typ[1].kind == nnkProcTy:
|
if typ.kind == nnkBracketExpr and typ.len > 1 and typ[1].kind == nnkProcTy:
|
||||||
return typ[1][1]
|
return typ[1][1]
|
||||||
elif typ.typeKind == ntyTypeDesc:
|
elif typ.typeKind == ntyTypeDesc:
|
||||||
let impl = typ[1].getImpl()
|
let impl = typ[1].getImpl()
|
||||||
|
|
@ -1319,6 +1319,8 @@ proc customPragmaNode(n: NimNode): NimNode =
|
||||||
if identDefs.kind == nnkRecCase:
|
if identDefs.kind == nnkRecCase:
|
||||||
identDefsStack.add(identDefs[0])
|
identDefsStack.add(identDefs[0])
|
||||||
for i in 1..<identDefs.len:
|
for i in 1..<identDefs.len:
|
||||||
|
# if it is and empty branch, skip
|
||||||
|
if identDefs[i][0].kind == nnkNilLit: continue
|
||||||
if identDefs[i][1].kind == nnkIdentDefs:
|
if identDefs[i][1].kind == nnkIdentDefs:
|
||||||
identDefsStack.add(identDefs[i][1])
|
identDefsStack.add(identDefs[i][1])
|
||||||
else: # nnkRecList
|
else: # nnkRecList
|
||||||
|
|
|
||||||
|
|
@ -154,3 +154,23 @@ block:
|
||||||
let a: proc(x: int) {.defaultValue(5).} = nil
|
let a: proc(x: int) {.defaultValue(5).} = nil
|
||||||
static:
|
static:
|
||||||
doAssert hasCustomPragma(a.type, defaultValue)
|
doAssert hasCustomPragma(a.type, defaultValue)
|
||||||
|
|
||||||
|
# bug #8371
|
||||||
|
template thingy {.pragma.}
|
||||||
|
|
||||||
|
type
|
||||||
|
Cardinal = enum
|
||||||
|
north, east, south, west
|
||||||
|
Something = object
|
||||||
|
a: float32
|
||||||
|
case cardinal: Cardinal
|
||||||
|
of north:
|
||||||
|
b {.thingy.}: int
|
||||||
|
of east:
|
||||||
|
c: int
|
||||||
|
of south: discard
|
||||||
|
else: discard
|
||||||
|
|
||||||
|
var foo: Something
|
||||||
|
foo.cardinal = north
|
||||||
|
doAssert foo.b.hasCustomPragma(thingy) == true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue