Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions compiler/closureiters.nim
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ proc collectExceptState(ctx: var Ctx, n: PNode): PNode {.inline.} =
if c.len > 1:
var cond: PNode = nil
for i in 0..<c.len - 1:
# `nkStmtList` means we hit a comma in a `FirstException, SecondException` expression.
# We skip it and go to the next child, which must be a `nkType` representing the next expection.
if c[i].kind == nkStmtList:
continue

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes no sense. The structure is supposed to be except-guard-A, except-guard-B, ..., [last] nkStmtList

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, this really is a silly take 😕 Somehow I thought that RangeDefect, Exception is traversed as nkType, nkStmtList, nkType, which is wrong, of course. I should have slept at this time of night probably instead of making blind guesses and spending CI cycles and your time.

In the PNode the nkExceptBranch that represents except RangeDefect, Exception looks like this:

except RangeDefect,
        ...   :tmpSlLower0 = Exception:
        ...   complete(retFutParamSym_603979901, result)
        ...   return nil

I.e. Exception is not represented as nkType at all, while it is a type. Maybe the problem is with PNode construction that happens earlier.

The structure is supposed to be except-guard-A, except-guard-B, ..., [last] nkStmtList

Yeah, matching each exception type individually works, no problem here. The problem is I can't match multiple exceptions in one except branch.

AFAIK matching multiple exception types is allowed and valid in except branches, so this should work.


assert(c[i].kind == nkType)
let nextCond = newTreeIT(nkCall, c.info, ctx.g.getSysType(c.info, tyBool),
newSymNode(g.getSysMagic(c.info, "of", mOf)),
Expand Down
21 changes: 21 additions & 0 deletions tests/iter/tclosureiters.nim
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ discard """
(3, 1)
(3, 2)
(3, 3)
32
'''
"""

Expand Down Expand Up @@ -174,3 +175,23 @@ iterator pairs(): (int, int) {.closure.} =

for pair in pairs():
echo pair

# bug #25921
when not defined(js):
import asyncdispatch

proc getNumber(): Future[int] {.async, raises: [RangeDefect, Exception].} =
32

proc getX(): Future[int] {.async.} =
let x =
try:
await getNumber()
except RangeDefect, Exception:
return

x

echo waitFor getX()
else:
echo 32
Loading