diff options
author | Dominik Picheta <dominikpicheta@googlemail.com> | 2014-05-04 21:04:07 +0100 |
---|---|---|
committer | Dominik Picheta <dominikpicheta@googlemail.com> | 2014-05-04 21:04:07 +0100 |
commit | 88cb4850cea651f78612a12e3fd3ba704109b0b7 (patch) | |
tree | 5110436c418d888016707aff3d89c9a8a50cd64c | |
parent | 93fed1f6d941fc42bd29e3edcef60b54f58a6f66 (diff) | |
parent | b1c865a656d6ee422f7d841a1e881874766a2b77 (diff) | |
download | Nim-88cb4850cea651f78612a12e3fd3ba704109b0b7.tar.gz |
Merge pull request #1175 from EXetoC/await-discard
Fix #1170.
-rw-r--r-- | lib/pure/asyncdispatch.nim | 3 | ||||
-rw-r--r-- | tests/async/tasyncdiscard.nim | 39 |
2 files changed, 41 insertions, 1 deletions
diff --git a/lib/pure/asyncdispatch.nim b/lib/pure/asyncdispatch.nim index fe9c16308..fcf947831 100644 --- a/lib/pure/asyncdispatch.nim +++ b/lib/pure/asyncdispatch.nim @@ -869,7 +869,8 @@ proc processBody(node, retFutureSym: PNimrodNode, else: discard of nnkDiscardStmt: # discard await x - if node[0][0].kind == nnkIdent and node[0][0].ident == !"await": + if node[0].kind != nnkEmpty and node[0][0].kind == nnkIdent and + node[0][0].ident == !"await": var newDiscard = node createVar("futureDiscard_" & $toStrLit(node[0][1]), node[0][1], newDiscard[0], newDiscard) diff --git a/tests/async/tasyncdiscard.nim b/tests/async/tasyncdiscard.nim new file mode 100644 index 000000000..48d8a8c4d --- /dev/null +++ b/tests/async/tasyncdiscard.nim @@ -0,0 +1,39 @@ +discard """ + output: ''' +1 +2 +3 +4 +1 +2 +1 +6 +''' +""" +import asyncio, asyncdispatch, asyncnet + +proc main {.async.} = + proc f: PFuture[int] {.async.} = + discard + echo 1 + discard + result = 2 + discard + + let x = await f() + echo x + echo 3 + + proc g: PFuture[int] {.async.} = + discard + echo 4 + discard + result = 6 + discard + echo await f() + discard await f() + + discard await g() + echo 6 + +main() |