summary refs log tree commit diff stats
path: root/tests/closure
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2018-12-05 23:42:40 +0100
committerAraq <rumpf_a@web.de>2018-12-06 08:06:54 +0100
commit7a0191ac7ea2c3adfa303cfd6b1d1759a361e5c7 (patch)
tree49768e92e17a353ee67a9762d3e8b1fc334d2db6 /tests/closure
parent467274a19aa77a4f2db5bed32425e2dc0ee71212 (diff)
downloadNim-7a0191ac7ea2c3adfa303cfd6b1d1759a361e5c7.tar.gz
fixes #9441
Diffstat (limited to 'tests/closure')
-rw-r--r--tests/closure/tinfer_closure_for_nestedproc.nim42
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/closure/tinfer_closure_for_nestedproc.nim b/tests/closure/tinfer_closure_for_nestedproc.nim
new file mode 100644
index 000000000..6450d1492
--- /dev/null
+++ b/tests/closure/tinfer_closure_for_nestedproc.nim
@@ -0,0 +1,42 @@
+discard """
+  action: compile
+"""
+
+# bug #9441
+import asyncdispatch, asyncfutures, strtabs
+
+type
+  Request = object
+  Context = object
+    position: int
+    accept: bool
+    headers: StringTableRef
+  Handler = proc (r: ref Request, c: Context): Future[Context]
+
+proc respond(req: Request): Future[void] = discard
+
+proc handle*(h: Handler): auto = # (proc (req: Request): Future[void]) =
+  proc server(req: Request): Future[void] {.async.} =
+    let emptyCtx = Context(
+      position: 0,
+      accept: true,
+      headers: newStringTable()
+    )
+    var reqHeap = new(Request)
+    reqHeap[] = req
+    var
+      f: Future[Context]
+      ctx: Context
+    try:
+      f = h(reqHeap, emptyCtx)
+      ctx = await f
+    except:
+      discard
+    if f.failed:
+      await req.respond()
+    else:
+      if not ctx.accept:
+        await req.respond()
+  return server
+
+waitFor handle(nil)(Request())