diff options
author | Anatoly Galiulin <galiulin.anatoly@gmail.com> | 2017-11-09 11:49:10 +0700 |
---|---|---|
committer | Anatoly Galiulin <galiulin.anatoly@gmail.com> | 2017-11-09 11:49:10 +0700 |
commit | 4812b0f0c585521142d78af5f6c8394d70c106b9 (patch) | |
tree | 9de9b95fa690926265d299ad9a20291ceeed8e83 /lib | |
parent | 46275f6b8fb448b51e68225fd42e69d53e65f562 (diff) | |
download | Nim-4812b0f0c585521142d78af5f6c8394d70c106b9.tar.gz |
Fix parameter types splitting in multisync macro #6708
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/asyncmacro.nim | 27 |
1 files changed, 8 insertions, 19 deletions
diff --git a/lib/pure/asyncmacro.nim b/lib/pure/asyncmacro.nim index 981190211..00d578941 100644 --- a/lib/pure/asyncmacro.nim +++ b/lib/pure/asyncmacro.nim @@ -472,27 +472,16 @@ proc stripAwait(node: NimNode): NimNode = proc splitParamType(paramType: NimNode, async: bool): NimNode = result = paramType if paramType.kind == nnkInfix and $paramType[0].ident in ["|", "or"]: - let firstType = paramType[1] - let firstTypeName = $firstType.ident - let secondType = paramType[2] - let secondTypeName = $secondType.ident + let firstAsync = "async" in ($paramType[1].ident).normalize + let secondAsync = "async" in ($paramType[2].ident).normalize # Make sure that at least one has the name `async`, otherwise we shouldn't # touch it. - if not ("async" in firstTypeName.normalize or - "async" in secondTypeName.normalize): - return - - if async: - if firstTypeName.normalize.startsWith("async"): - result = paramType[1] - elif secondTypeName.normalize.startsWith("async"): - result = paramType[2] - else: - if not firstTypeName.normalize.startsWith("async"): - result = paramType[1] - elif not secondTypeName.normalize.startsWith("async"): - result = paramType[2] + + if firstAsync: + result = paramType[if async: 1 else: 2] + elif secondAsync: + result = paramType[if async: 2 else: 1] proc stripReturnType(returnType: NimNode): NimNode = # Strip out the 'Future' from 'Future[T]'. @@ -535,4 +524,4 @@ macro multisync*(prc: untyped): untyped = let (sync, asyncPrc) = splitProc(prc) result = newStmtList() result.add(asyncSingleProc(asyncPrc)) - result.add(sync) \ No newline at end of file + result.add(sync) |