Skip to content

[lua] Replace IIFE discard with local _ assignment#12741

Open
jdonaldson wants to merge 1 commit intoHaxeFoundation:developmentfrom
jdonaldson:lua-local-discard
Open

[lua] Replace IIFE discard with local _ assignment#12741
jdonaldson wants to merge 1 commit intoHaxeFoundation:developmentfrom
jdonaldson:lua-local-discard

Conversation

@jdonaldson
Copy link
Member

@jdonaldson jdonaldson commented Mar 5, 2026

Summary

  • Replace (function() return expr end)() with local _ = expr for discarded expression-statements in gen_iife_assign
  • Affects TBinop(op != Assign) and TField at statement level in gen_block_element
  • Simpler output, no closure overhead, avoids Lua's (-at-statement-start parsing ambiguity

Relates to #7350

Test plan

  • All Lua unit tests pass (11,709 assertions)
  • No (function() return patterns remain from gen_iife_assign
  • 48 local _ = replacements in test output

Replace `(function() return expr end)()` with `local _ = expr` for
discarded expression-statements (non-assign TBinop and TField at
statement level). This eliminates the most common source of
`(`-starting statements that trigger Lua's parsing ambiguity.

Also adds deferred semicolon mechanism for remaining cases where
generated output starts with `(` (chained calls, anonymous IIFEs).
@jdonaldson
Copy link
Member Author

I'm trying to chip away at a few of the points where genlua creates a mess of expressions. One easy one is avoiding iifes for simple expressions that don't save return values.

@skial skial mentioned this pull request Mar 5, 2026
1 task
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.

1 participant