Skip to content

Commit 7c012cb

Browse files
committed
fixes #3356
1 parent ec357a3 commit 7c012cb

File tree

1 file changed

+20
-11
lines changed

1 file changed

+20
-11
lines changed

lib/pure/asyncdispatch.nim

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1468,24 +1468,33 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
14681468
hint("Processing " & prc[0].getName & " as an async proc.")
14691469

14701470
let returnType = prc[3][0]
1471+
var baseType: NimNode
14711472
# Verify that the return type is a Future[T]
1472-
if returnType.kind == nnkIdent:
1473-
error("Expected return type of 'Future' got '" & $returnType & "'")
1474-
elif returnType.kind == nnkBracketExpr:
1475-
if $returnType[0] != "Future":
1476-
error("Expected return type of 'Future' got '" & $returnType[0] & "'")
1473+
if returnType.kind == nnkBracketExpr:
1474+
let fut = repr(returnType[0])
1475+
if fut != "Future":
1476+
error("Expected return type of 'Future' got '" & fut & "'")
1477+
baseType = returnType[1]
1478+
elif returnType.kind in nnkCallKinds and $returnType[0] == "[]":
1479+
let fut = repr(returnType[1])
1480+
if fut != "Future":
1481+
error("Expected return type of 'Future' got '" & fut & "'")
1482+
baseType = returnType[2]
1483+
elif returnType.kind == nnkEmpty:
1484+
baseType = returnType
1485+
else:
1486+
error("Expected return type of 'Future' got '" & repr(returnType) & "'")
14771487

14781488
let subtypeIsVoid = returnType.kind == nnkEmpty or
1479-
(returnType.kind == nnkBracketExpr and
1480-
returnType[1].kind == nnkIdent and returnType[1].ident == !"void")
1489+
(baseType.kind == nnkIdent and returnType[1].ident == !"void")
14811490

14821491
var outerProcBody = newNimNode(nnkStmtList, prc[6])
14831492

14841493
# -> var retFuture = newFuture[T]()
14851494
var retFutureSym = genSym(nskVar, "retFuture")
14861495
var subRetType =
14871496
if returnType.kind == nnkEmpty: newIdentNode("void")
1488-
else: returnType[1]
1497+
else: baseType
14891498
outerProcBody.add(
14901499
newVarStmt(retFutureSym,
14911500
newCall(
@@ -1509,7 +1518,7 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
15091518
newIdentNode("off")))) # -> {.push warning[resultshadowed]: off.}
15101519

15111520
procBody.insert(1, newNimNode(nnkVarSection, prc[6]).add(
1512-
newIdentDefs(newIdentNode("result"), returnType[1]))) # -> var result: T
1521+
newIdentDefs(newIdentNode("result"), baseType))) # -> var result: T
15131522

15141523
procBody.insert(2, newNimNode(nnkPragma).add(
15151524
newIdentNode("pop"))) # -> {.pop.})
@@ -1550,8 +1559,8 @@ proc asyncSingleProc(prc: NimNode): NimNode {.compileTime.} =
15501559
result[6] = outerProcBody
15511560

15521561
#echo(treeRepr(result))
1553-
if prc[0].getName == "hubConnectionLoop":
1554-
echo(toStrLit(result))
1562+
#if prc[0].getName == "hubConnectionLoop":
1563+
# echo(toStrLit(result))
15551564

15561565
macro async*(prc: stmt): stmt {.immediate.} =
15571566
## Macro which processes async procedures into the appropriate

0 commit comments

Comments
 (0)