fix try/finally rethrow when try block has return paths#1699
Open
RealColdFry wants to merge 1 commit intoTypeScriptToLua:masterfrom
Open
fix try/finally rethrow when try block has return paths#1699RealColdFry wants to merge 1 commit intoTypeScriptToLua:masterfrom
RealColdFry wants to merge 1 commit intoTypeScriptToLua:masterfrom
Conversation
Fixes a regression from TypeScriptToLua#1692 where try/finally (no catch) with both return and throw paths silently lost the error. The re-throw used an undeclared ____error variable; use ____hasReturned instead, which is where pcall places the error on failure.
lolleko
reviewed
Mar 28, 2026
Member
lolleko
left a comment
There was a problem hiding this comment.
I think this makes sense and it's good we have a lot of tests for this, as there are so many edge cases.
I would even at at least one more tests and double check we really have all combinations covered by tests.
So this is less likely to regress again.
| try { foo(); return "no error"; } catch(e) { return e; } | ||
| `.expectToMatchJsResult(); | ||
| }); | ||
|
|
Member
There was a problem hiding this comment.
Can we have one more test for return + throw + non-empty finally body
function foo(shouldReturn: boolean) {
try {
if (shouldReturn) return "ok";
throw "err";
} finally {
sideEffect = true; // must still run on both paths
}
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes a regression from #1692 where try/finally (no catch) with both return and throw paths silently lost the error. The re-throw used an undeclared
____errorvariable; use____hasReturnedinstead, which is wherepcallplaces the error on failure.