Skip to content

Compiler: Closure iterators: Handle comma in multi-exception except variant#25922

Closed
moigagoo wants to merge 5 commits into
nim-lang:develfrom
moigagoo:bugfix/25921_fix_multiple_exceptions_in_except_in_assignments_in_async_procs
Closed

Compiler: Closure iterators: Handle comma in multi-exception except variant#25922
moigagoo wants to merge 5 commits into
nim-lang:develfrom
moigagoo:bugfix/25921_fix_multiple_exceptions_in_except_in_assignments_in_async_procs

Conversation

@moigagoo

Copy link
Copy Markdown
Contributor

Closes #25921

Comment thread compiler/closureiters.nim
# `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.

@moigagoo moigagoo marked this pull request as draft June 18, 2026 03:07
@moigagoo

Copy link
Copy Markdown
Contributor Author

Fixed in devel.

@moigagoo moigagoo closed this Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multiple exception can't be caught in one except in assignment block in an async proc

2 participants