Skip to content

Commit

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

* add a generic object for custom pragma

(cherry picked from commit 1563cb2)
  • Loading branch information
Clonkk authored and narimiran committed Apr 24, 2023
1 parent fe5edb7 commit 70478d3
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 @@ -1551,7 +1551,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 70478d3

Please sign in to comment.