Skip to content

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

Open
RealColdFry wants to merge 5 commits intoTypeScriptToLua:masterfrom
RealColdFry:fix/async-try-control-flow
Open

fix return, break and continue inside try in async functions (#1706)#1707
RealColdFry wants to merge 5 commits intoTypeScriptToLua: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.

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