Skip to content

fix: use intersection type for table.pack return type - #1023

Merged
CppCXY merged 1 commit into
EmmyLuaLs:mainfrom
EfveZombie:fix.table_pack_return_type
Apr 7, 2026
Merged

CppCXY merged 1 commit into
EmmyLuaLs:mainfrom
EfveZombie:fix.table_pack_return_type

Conversation

@EfveZombie

Copy link
Copy Markdown

Problem

The return type of table.pack was defined as [T...] | { n: integer }, which uses a union type. This implies the return value is either a tuple or a table with an n field — but in reality, table.pack always returns a table that has both integer-indexed elements and the n field simultaneously.

Solution

Changed the return type from union (|) to intersection (&):

-- Before
---@return [T...] | { n: integer }

-- After
---@return [T...] & { n: integer }

This correctly expresses that the returned table has both tuple elements and the n field at the same time, which:

  • Preserves per-element type inference from [T...]
  • Makes the n field visible alongside array index members
  • Matches the actual runtime behavior of table.pack

…s that it has both tuple elements and n field

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the return type annotation for the table.pack function in the Lua standard library definitions. The change replaces the union operator with an intersection operator to correctly indicate that the returned table contains both the packed elements and the 'n' field. I have no feedback to provide as there were no review comments.

@CppCXY
CppCXY merged commit eeb90e3 into EmmyLuaLs:main Apr 7, 2026
16 checks passed
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