Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
nitely committed Jan 5, 2025
1 parent 2689ab2 commit 3f4b553
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
14 changes: 7 additions & 7 deletions lib/pure/asyncmacro.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 21 additions & 1 deletion tests/async/tasync_error_tracking.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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.}

Expand Down Expand Up @@ -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())

0 comments on commit 3f4b553

Please sign in to comment.