Skip to content

fix await inside catch/finally in async try (#1659)#1709

Merged
Perryvw merged 3 commits into
TypeScriptToLua:masterfrom
RealColdFry:fix/async-try-await-in-catch-finally
Apr 18, 2026
Merged

fix await inside catch/finally in async try (#1659)#1709
Perryvw merged 3 commits into
TypeScriptToLua:masterfrom
RealColdFry:fix/async-try-await-in-catch-finally

Conversation

@RealColdFry
Copy link
Copy Markdown
Contributor

Fixes #1659

  • wrap catch and finally callbacks in __TS__AsyncAwaiter so await works inside them
  • fix the chain ordering (.catch() before .finally()) and wire up the full chain before awaiting.

@RealColdFry RealColdFry marked this pull request as ready for review April 15, 2026 10:18
@RealColdFry RealColdFry changed the title fix await inside catch/finally in async try fix await inside catch/finally in async try (#1659) Apr 16, 2026
await failing();
} catch (e) {
log("catch");
const a = await Promise.resolve(true);
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.

Could you add a test where this promise is not instantly resolved, and its return value is returned to run? Something like:

try {
    await failing();
    return "succeeded";
} catch (e) {
    return await somePromiseResolvedLater();
}

and then resolving the promise after rejecting the first one

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.

Reconciles with TypeScriptToLua#1707 (return/break/continue inside try in async). The
merged transformAsyncTry wraps catch and finally in __TS__AsyncAwaiter
(so await works inside them) and chains them via reassignment to ____try
before the final __TS__Await, while preserving the new
hasReturn/hasBreak/hasContinue flag tracking and post-checks.
@Perryvw Perryvw merged commit 3d14be8 into TypeScriptToLua:master Apr 18, 2026
5 checks passed
@RealColdFry RealColdFry deleted the fix/async-try-await-in-catch-finally branch April 22, 2026 01:52
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.

Async catch block may yield from outside a coroutine

2 participants