Skip to content

Conversation

@MineRobber9000
Copy link

@MineRobber9000 MineRobber9000 commented Jan 11, 2026

Basically, in a few places moonscript will do:

tbl = {"foo", nil, "bar", "baz"}

And expect #tbl to be 4. While this was never guaranteed behavior in Lua (the reference manual states that any table border can be returned in this case), under PUC-Rio Lua <5.5 (and LuaJIT, which presumably emulates the behavior of PUC-Rio Lua 5.1), it would work correctly. However, with the update to 5.5, this has now broken. As a result, some things that worked under previous versions no longer do.

I've made changes in 3 places to fix this:

  • Added moon.len, a function which returns the largest integer key in a table
  • Fixed the unpack call in moonscript.transform.class to unpack indices 2 to 4, instead of leaving the last index as #node
  • Fixed the moon.type test in spec.moon_spec to use moon.len.

I've also added 5.5.0 to the spec matrix and set luarocks to use 3.13.0, which supports Lua 5.5.

A temporary measure, until argparse gets updated to support 5.5.
Basically, in a few places moonscript will do:

```
tbl = {"foo", nil, "bar", "baz"}
```

And expect `#tbl` to be `4`. While this was never guaranteed behavior in Lua
(the reference manual states that *any* table border can be returned in this
case), under PUC-Rio Lua <5.5 (and LuaJIT, which presumably emulates the
behavior of PUC-Rio Lua 5.1), it would work correctly. However, with the update
to 5.5, this has now broken. As a result, some things that worked under
previous versions no longer do.

I've made changes in 3 places to fix this:

- Added `moon.len`, a function which returns the largest integer key in a table
- Fixed the `unpack` call in `moonscript.transform.class` to unpack indices 2
to 4, instead of leaving the last index as `#node`
- Fixed the `moon.type` test in `spec.moon_spec` to use `moon.len`.
@MineRobber9000 MineRobber9000 changed the title Fix incompatibilities with Lua 5.5 WIP: Fix incompatibilities with Lua 5.5 Jan 11, 2026
@MineRobber9000 MineRobber9000 marked this pull request as draft January 11, 2026 00:59
@MineRobber9000
Copy link
Author

Marking this as draft since argparse needs to be updated to work with 5.5 (should just be as simple as pushing an update with the lua dependency updated).

end
fold = function(items, fn)
local len = #items
len = #items
Copy link

@vendethiel vendethiel Jan 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like a bug being introduced

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing in moon/init.moon actually uses this new function, so reusing the same local variable for it and the local here isn't really in conflict (at least, that's why I presume moonscript removed the local from this line; admittedly I just ran moonc over it and then ran busted to make sure I hadn't broken anything else).

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