mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
accept object type node from macros (#19179)
This commit is contained in:
@@ -2856,7 +2856,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
|
||||
of nkBind:
|
||||
message(c.config, n.info, warnDeprecated, "bind is deprecated")
|
||||
result = semExpr(c, n[0], flags)
|
||||
of nkTypeOfExpr, nkTupleTy, nkTupleClassTy, nkRefTy..nkEnumTy, nkStaticTy:
|
||||
of nkTypeOfExpr..nkTupleClassTy, nkStaticTy, nkRefTy..nkEnumTy:
|
||||
if c.matchedConcept != nil and n.len == 1:
|
||||
let modifier = n.modifierTypeKindOfNode
|
||||
if modifier != tyNone:
|
||||
|
||||
16
tests/macros/ttypenodes.nim
Normal file
16
tests/macros/ttypenodes.nim
Normal file
@@ -0,0 +1,16 @@
|
||||
import macros
|
||||
|
||||
macro makeEnum(): untyped =
|
||||
newTree(nnkEnumTy, newEmptyNode(), ident"a", ident"b", ident"c")
|
||||
|
||||
macro makeObject(): untyped =
|
||||
newTree(nnkObjectTy, newEmptyNode(), newEmptyNode(), newTree(nnkRecList,
|
||||
newTree(nnkIdentDefs, ident"x", ident"y", ident"int", newEmptyNode())))
|
||||
|
||||
type
|
||||
Foo = makeEnum()
|
||||
Bar = makeObject()
|
||||
|
||||
doAssert {a, b, c} is set[Foo]
|
||||
let bar = Bar(x: 3, y: 4)
|
||||
doAssert (bar.x, bar.y) == (3, 4)
|
||||
Reference in New Issue
Block a user