Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

while loop + break compilation bug #39

Open
elisee opened this issue May 5, 2014 · 1 comment
Open

while loop + break compilation bug #39

elisee opened this issue May 5, 2014 · 1 comment

Comments

@elisee
Copy link
Contributor

elisee commented May 5, 2014

I encountered this bug while compiling to JS real-life Lua. This minimal code triggers it:

function a() end
while true do
    break
end

This gets compiled to:

G.str['a'] = (function () {
  var tmp;

  return [];
})
while (true) (function() {
  return;
})();

Notice the immediately-invoked function expression (IIFE) inside the while loop in the generated JS code. The Lua break statement is compiled into a return call but all it does is leave the function body, not the loop. So the loop, which should exit immediately, runs forever (and locks up the browser).

The Lua function declaration function a() end at the top is required to trigger the insertion of the IIFE and thus the bug.

@elisee
Copy link
Contributor Author

elisee commented May 5, 2014

Looks like the bug comes from here: https://github.com/mherkender/lua.js/blob/master/src/lua.jison#L298

I'm not familiar with Jison so I'd rather not try and fix it myself as I'm likely to botch something else accidentally.

The while statement should probably be generated inside the generated IIFE. There are questions about how that might interact with the condition scoping though? Not sure.

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

No branches or pull requests

1 participant