From 4812b0f0c585521142d78af5f6c8394d70c106b9 Mon Sep 17 00:00:00 2001 From: Anatoly Galiulin Date: Thu, 9 Nov 2017 11:49:10 +0700 Subject: [PATCH 1/2] Fix parameter types splitting in multisync macro #6708 --- lib/pure/asyncmacro.nim | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/lib/pure/asyncmacro.nim b/lib/pure/asyncmacro.nim index 981190211d..00d5789419 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) From d02606064cdfedd3822ddee7dbee341dd5a09b40 Mon Sep 17 00:00:00 2001 From: Anatoly Galiulin Date: Mon, 13 Nov 2017 15:16:44 +0700 Subject: [PATCH 2/2] Remove unneeded comment #6708 --- lib/pure/asyncmacro.nim | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/pure/asyncmacro.nim b/lib/pure/asyncmacro.nim index 00d5789419..a8e378d5c4 100644 --- a/lib/pure/asyncmacro.nim +++ b/lib/pure/asyncmacro.nim @@ -475,9 +475,6 @@ proc splitParamType(paramType: NimNode, async: bool): NimNode = 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 firstAsync: result = paramType[if async: 1 else: 2] elif secondAsync: