Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept object type node from macros #19179

Merged
merged 1 commit into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions tests/macros/ttypenodes.nim
Original file line number Diff line number Diff line change
@@ -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)