Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* Apply commit nim-lang@5da931f that was never merged (was part of a bigger PR). Should fix issue nim-lang#11932

* add a generic object for custom pragma
  • Loading branch information
Clonkk authored and PMunch committed Mar 28, 2022
1 parent ce3c80c commit 58ef8e4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/core/macros.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,12 @@ proc customPragmaNode(n: NimNode): NimNode =
if n.kind in {nnkDotExpr, nnkCheckedFieldExpr}:
let name = $(if n.kind == nnkCheckedFieldExpr: n[0][1] else: n[1])
let typInst = getTypeInst(if n.kind == nnkCheckedFieldExpr or n[0].kind == nnkHiddenDeref: n[0][0] else: n[0])
var typDef = getImpl(if typInst.kind == nnkVarTy: typInst[0] else: typInst)
var typDef = getImpl(
if typInst.kind == nnkVarTy or
typInst.kind == nnkBracketExpr:
typInst[0]
else: typInst
)
while typDef != nil:
typDef.expectKind(nnkTypeDef)
let typ = typDef[2]
Expand Down
10 changes: 10 additions & 0 deletions tests/pragmas/tcustom_pragma.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,21 @@ block:
MyObj = object
myField1, myField2 {.myAttr: "hi".}: int

MyGenericObj[T] = object
myField1, myField2 {.myAttr: "hi".}: int


var o: MyObj
static:
doAssert o.myField2.hasCustomPragma(myAttr)
doAssert(not o.myField1.hasCustomPragma(myAttr))

var ogen: MyGenericObj[int]
static:
doAssert ogen.myField2.hasCustomPragma(myAttr)
doAssert(not ogen.myField1.hasCustomPragma(myAttr))


import custom_pragma
block: # A bit more advanced case
type
Expand Down

0 comments on commit 58ef8e4

Please sign in to comment.