diff --git a/lib/pure/asyncmacro.nim b/lib/pure/asyncmacro.nim index 0ba99cfadabf..5783bde23071 100644 --- a/lib/pure/asyncmacro.nim +++ b/lib/pure/asyncmacro.nim @@ -456,15 +456,15 @@ macro multisync*(prc: untyped): untyped = result.add(sync) macro toFutureEx*(prc: typed): untyped = - # XXX error instead of asserts - #echo repr getRaisesList(prc[0]) - #assert prc.kind == nnkCall + template check(cond: untyped): untyped = + if not cond: + error("async proc call expected", prc) + check prc.kind == nnkCall + check prc[0].kind == nnkSym + check isAsyncPrc(prc[0].getImpl) let procImpl = getTypeImpl(prc[0]) - #assert procImpl.kind == nnkProcTy + check procImpl.kind == nnkProcTy let retTyp = procImpl.params[0] - #assert retTyp.kind == nnkBracketExpr - #let fut = repr(retTyp[0]) - #assert fut == "FutureUntracked", fut let baseTyp = retTyp[1] let raisesList = getRaisesList(prc[0]) let exTyp = if raisesList.len == 0: diff --git a/tests/async/tasync_error_tracking.nim b/tests/async/tasync_error_tracking.nim index 929d107c420c..54e5e8cf1867 100644 --- a/tests/async/tasync_error_tracking.nim +++ b/tests/async/tasync_error_tracking.nim @@ -45,7 +45,9 @@ block: discard block: - # XXX raises: [] + # we cannot tell if fcb is an async proc + # or a closure that returns a user created newFuture() + # that can raise anything type FooBar = object fcb: proc(): Future[void] {.closure, gcsafe.} @@ -123,3 +125,21 @@ block: await fut() doAssert compiles(good()) doAssert not compiles(bad()) + +block: + proc bar() {.async.} = + err(false) + + # XXX We could check all returns are from async procs + # and if so use the inferred proc raises + proc foo(): Future[void] = + bar() + + template good = + proc main {.async, raises: [Exception].} = + await foo() + template bad = + proc main {.async, raises: [MyError].} = + await foo() + doAssert compiles(good()) + doAssert not compiles(bad())