Skip to content

Lua 5.0: Fix bad unpack() call in SparseArraySpread#1347

Merged
Perryvw merged 1 commit intoTypeScriptToLua:masterfrom
YoRyan:fix-lua50-unpack
Sep 17, 2022
Merged

Lua 5.0: Fix bad unpack() call in SparseArraySpread#1347
Perryvw merged 1 commit intoTypeScriptToLua:masterfrom
YoRyan:fix-lua50-unpack

Conversation

@YoRyan
Copy link
Copy Markdown
Contributor

@YoRyan YoRyan commented Sep 15, 2022

For the 5.0 target, we are currently transpiling the SparseArraySpread lualib feature as:

local function __TS__SparseArraySpread(sparseArray)
    return unpack(nil, sparseArray, 1, sparseArray.sparseLength)
end

The nil argument causes runtime errors and should not be there; unpack() takes 3 arguments. Or, rather, it does in all versions of Lua except 5.0, which does not support the optional i and j arguments that specify the start and end of the unpacked slice.

So we need to add a polyfill that supports i and j, and also convinces the type checker that it's okay to call unpack() without a leading nil.

@Perryvw Perryvw merged commit a221972 into TypeScriptToLua:master Sep 17, 2022
@YoRyan YoRyan deleted the fix-lua50-unpack branch October 27, 2022 05:16
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.

2 participants