Skip to content

fix return, break and continue inside try in async functions (#1706)#1707

Merged
Perryvw merged 5 commits into
TypeScriptToLua:masterfrom
RealColdFry:fix/async-try-control-flow
Apr 16, 2026
Merged

fix return, break and continue inside try in async functions (#1706)#1707
Perryvw merged 5 commits into
TypeScriptToLua:masterfrom
RealColdFry:fix/async-try-control-flow

Conversation

@RealColdFry
Copy link
Copy Markdown
Contributor

@RealColdFry RealColdFry commented Apr 6, 2026

Fixes #1706

  • replaces return/break/continue inside async try/catch with flag variables checked after the awaiter resolves
  • nested try-in-try not yet handled

@RealColdFry RealColdFry marked this pull request as ready for review April 6, 2026 05:00
Comment thread src/transformation/visitors/return.ts Outdated
),
];
if (results.length > 0) {
stmts.push(lua.createAssignmentStatement(lua.createIdentifier("____returnValue"), results[0], statement));
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.

Guess this breaks for multi-return, any easy wayt to serve those cases? (otherwise I'm okay with merging the easier change first)

Copy link
Copy Markdown
Contributor Author

@RealColdFry RealColdFry Apr 14, 2026

Choose a reason for hiding this comment

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

multi-return actuallyy works here 20b205dc because the multi-return values are wrapped into a single table before storage so results[0] captures everything. But it was somewhat confusing and relied on implicit assumptions so I split out transformReturnExpressionForTryCatch which returns a single lua.Expression instead of indexing into an array.

@Perryvw Perryvw merged commit 5753d6c into TypeScriptToLua:master Apr 16, 2026
5 checks passed
RealColdFry added a commit to RealColdFry/TypeScriptToLua that referenced this pull request Apr 17, 2026
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.
@RealColdFry RealColdFry deleted the fix/async-try-control-flow 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.

return, break and continue inside try in async functions don't work correctly

2 participants