Skip to content

Commit

Permalink
Handle multiple childs for opensymchoice (#266)
Browse files Browse the repository at this point in the history
And more tests. Follow up of #261
  • Loading branch information
Menduist authored May 5, 2022
1 parent 5a906ad commit ae19d5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 3 additions & 4 deletions chronos/asyncmacro2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,9 @@ proc cleanupOpenSymChoice(node: NimNode): NimNode {.compileTime.} =
# ref https://github.com/nim-lang/Nim/issues/11091
if node.kind in nnkCallKinds and
node[0].kind == nnkOpenSymChoice and node[0].eqIdent("[]"):
result = newNimNode(nnkBracketExpr).add(
cleanupOpenSymChoice(node[1]),
cleanupOpenSymChoice(node[2])
)
result = newNimNode(nnkBracketExpr)
for child in node[1..^1]:
result.add(cleanupOpenSymChoice(child))
else:
result = node.copyNimNode()
for child in node:
Expand Down
7 changes: 7 additions & 0 deletions tests/testmacro.nim
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,10 @@ suite "Macro transformations test suite":
type OpenObject = object
macroAsync(testMacro, seq, OpenObject)
check waitFor(testMacro()).len == 0

macro macroAsync2(name, restype, inner1, inner2, inner3, inner4: untyped): untyped =
quote do:
proc `name`(): Future[`restype`[`inner1`[`inner2`[`inner3`, `inner4`]]]] {.async.} = return

macroAsync2(testMacro2, seq, Opt, Result, OpenObject, cstring)
check waitFor(testMacro2()).len == 0

0 comments on commit ae19d5b

Please sign in to comment.