diff options
author | Yuriy Glukhov <yglukhov@users.noreply.github.com> | 2018-07-22 23:30:59 +0300 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2018-07-22 22:30:59 +0200 |
commit | 20942098378d12d2b2041cb916c0925b6f017a98 (patch) | |
tree | abb9f868211da13acd4a628f0234c744ce10e964 | |
parent | 9379f9353a73acdb9744ab96c0544fb446b11a6a (diff) | |
download | Nim-20942098378d12d2b2041cb916c0925b6f017a98.tar.gz |
Fixed #8399 (#8401)
-rw-r--r-- | compiler/closureiters.nim | 2 | ||||
-rw-r--r-- | tests/async/t6100.nim | 15 | ||||
-rw-r--r-- | tests/async/t7985.nim | 19 | ||||
-rw-r--r-- | tests/async/tasync_misc.nim | 47 |
4 files changed, 48 insertions, 35 deletions
diff --git a/compiler/closureiters.nim b/compiler/closureiters.nim index 6fa856b2f..9e4885b66 100644 --- a/compiler/closureiters.nim +++ b/compiler/closureiters.nim @@ -588,7 +588,7 @@ proc lowerStmtListExprs(ctx: var Ctx, n: PNode, needsSplit: var bool): PNode = let branch = n[i] case branch.kind of nkOfBranch: - branch[1] = ctx.convertExprBodyToAsgn(branch[1], tmp) + branch[^1] = ctx.convertExprBodyToAsgn(branch[^1], tmp) of nkElse: branch[0] = ctx.convertExprBodyToAsgn(branch[0], tmp) else: diff --git a/tests/async/t6100.nim b/tests/async/t6100.nim deleted file mode 100644 index b4dc0f146..000000000 --- a/tests/async/t6100.nim +++ /dev/null @@ -1,15 +0,0 @@ -discard """ - file: "t6100.nim" - exitcode: 0 - output: "10000000" -""" -import asyncdispatch - -let done = newFuture[int]() -done.complete(1) - -proc asyncSum: Future[int] {.async.} = - for _ in 1..10_000_000: - result += await done - -echo waitFor asyncSum() \ No newline at end of file diff --git a/tests/async/t7985.nim b/tests/async/t7985.nim deleted file mode 100644 index 0365499d3..000000000 --- a/tests/async/t7985.nim +++ /dev/null @@ -1,19 +0,0 @@ -discard """ - file: "t7985.nim" - exitcode: 0 - output: "(value: 1)" -""" -import json, asyncdispatch - -proc getData(): Future[JsonNode] {.async.} = - result = %*{"value": 1} - -type - MyData = object - value: BiggestInt - -proc main() {.async.} = - let data = to(await(getData()), MyData) - echo data - -waitFor(main()) diff --git a/tests/async/tasync_misc.nim b/tests/async/tasync_misc.nim new file mode 100644 index 000000000..695dcd98a --- /dev/null +++ b/tests/async/tasync_misc.nim @@ -0,0 +1,47 @@ +discard """ + exitcode: 0 + output: "ok" +""" + +import json, asyncdispatch +block: #6100 + let done = newFuture[int]() + done.complete(1) + + proc asyncSum: Future[int] {.async.} = + for _ in 1..10_000_000: + result += await done + + let res = waitFor asyncSum() + doAssert(res == 10000000) + +block: #7985 + proc getData(): Future[JsonNode] {.async.} = + result = %*{"value": 1} + + type + MyData = object + value: BiggestInt + + proc main() {.async.} = + let data = to(await(getData()), MyData) + doAssert($data == "(value: 1)") + + waitFor(main()) + +block: #8399 + proc bar(): Future[string] {.async.} = discard + + proc foo(line: string) {.async.} = + var res = + case line[0] + of '+', '-': @[] + of '$': (let x = await bar(); @[""]) + else: + nil + + doAssert(res == @[""]) + + waitFor foo("$asd") + +echo "ok" |