Skip to content

Commit 1563cb2

Browse files
authored
Fix #11923 (#19427)
* Apply commit 5da931f that was never merged (was part of a bigger PR). Should fix issue #11932 * add a generic object for custom pragma
1 parent 927fa89 commit 1563cb2

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/core/macros.nim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1523,7 +1523,12 @@ proc customPragmaNode(n: NimNode): NimNode =
15231523
if n.kind in {nnkDotExpr, nnkCheckedFieldExpr}:
15241524
let name = $(if n.kind == nnkCheckedFieldExpr: n[0][1] else: n[1])
15251525
let typInst = getTypeInst(if n.kind == nnkCheckedFieldExpr or n[0].kind == nnkHiddenDeref: n[0][0] else: n[0])
1526-
var typDef = getImpl(if typInst.kind == nnkVarTy: typInst[0] else: typInst)
1526+
var typDef = getImpl(
1527+
if typInst.kind == nnkVarTy or
1528+
typInst.kind == nnkBracketExpr:
1529+
typInst[0]
1530+
else: typInst
1531+
)
15271532
while typDef != nil:
15281533
typDef.expectKind(nnkTypeDef)
15291534
let typ = typDef[2]

tests/pragmas/tcustom_pragma.nim

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,21 @@ block:
1717
MyObj = object
1818
myField1, myField2 {.myAttr: "hi".}: int
1919

20+
MyGenericObj[T] = object
21+
myField1, myField2 {.myAttr: "hi".}: int
22+
23+
2024
var o: MyObj
2125
static:
2226
doAssert o.myField2.hasCustomPragma(myAttr)
2327
doAssert(not o.myField1.hasCustomPragma(myAttr))
2428

29+
var ogen: MyGenericObj[int]
30+
static:
31+
doAssert ogen.myField2.hasCustomPragma(myAttr)
32+
doAssert(not ogen.myField1.hasCustomPragma(myAttr))
33+
34+
2535
import custom_pragma
2636
block: # A bit more advanced case
2737
type

0 commit comments

Comments
 (0)