Handle multiple childs for opensymchoice (#266)

And more tests. Follow up of #261
This commit is contained in:
Tanguy 2022-05-05 11:05:04 +02:00 committed by GitHub
parent 5a906ad56c
commit ae19d5b6f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View File

@ -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:

View File

@ -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