mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-02 03:02:31 +00:00
* Apply commit5da931fe81that was never merged (was part of a bigger PR). Should fix issue #11932 * add a generic object for custom pragma (cherry picked from commit1563cb2f6e)
This commit is contained in:
committed by
narimiran
parent
fe5edb7ab0
commit
70478d34e3
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user