xiangnanscu / js2lua

js2lua Writing LuaJIT with the expressiveness of JavaScript.
https://xiangnanscu.github.io/js2lua/
3 stars 0 forks source link

Ambiguous functon call in for loops #3

Closed al1-ce closed 1 month ago

al1-ce commented 1 month ago

Discovered when I was rewriting typescript-to-lua code. If you have a function call as last statement in for loop then interpreter (neovim's) complains about ambiguous functon call.

// input.js
    for (let i = 0; i < array; ++i) {
        somefunc(array[i + 1]);
        // let _nil; // this is a quick fix for this issue
    }
-- output.lua
    do
        local i = 0
        while i < #array do
            somefunc(array[i + 1]) -- can also insert ; here to fix issue
            -- local _nil -- generated from fix
            (function() -- <- AMBIGUOUS FUNCTION CALL
                i = i + 1
                return i
            end)()
        end
    end
al1-ce commented 1 month ago

Possible solution I'd propose is inserting semicolon after each statement with option to enable/disable that with flags