Skip to content

fix(js): keep finally blocks reachable after return or throw (#172) - #205

Merged
DaisukeYoda merged 4 commits into
mainfrom
fix/172-finally-reachability
Oct 15, 2026
Merged

DaisukeYoda merged 4 commits into
mainfrom
fix/172-finally-reachability

Conversation

@DaisukeYoda

@DaisukeYoda DaisukeYoda commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Fixes #172.

A finally block runs however its try or catch ends. The CFG builder connected the try and catch to the finally block only when they completed normally, so a finally after a return, throw, break or continue was reported as unreachable_branch.

The builder now adds an exception edge into the finally block from the try block, or from the catch block when there is one. That edge stands for every abrupt exit, so the finally block is reachable whenever the try is. The finally block connects to the code after the try only when the end of the try or catch is reachable from the start of the try and does not end with a jump, so after() in try { return } finally { ... } after() is still reported. Exception edges do not count toward cyclomatic complexity, so complexity does not change.

@DaisukeYoda
DaisukeYoda force-pushed the fix/172-finally-reachability branch from cb87132 to 9abfc85 Compare October 15, 2026 02:19
@DaisukeYoda
DaisukeYoda merged commit 35fe0ce into main Oct 15, 2026
4 checks passed
@DaisukeYoda
DaisukeYoda deleted the fix/172-finally-reachability branch October 15, 2026 02:21
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.

[BUG][auto] ts/finally-block-reported-unreachable: statements in a finally block are reported unreachable when the try or catch block returns or throws

1 participant