LuaLS / LuaLS/lua-language-server

lua-language-server not detecting types when destructuring Tuple types with ~table.unpack~

Open
#2,873 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

### How are you using the lua-language-server?

Other

### Which OS are you using?

Windows

### What is the issue affecting?

Diagnostics/Syntax Checking

### Expected Behaviour

I might be wrong here, but I assume this should work?
Language server should detect the types from the defined tuple:

```lua
---@alias my_tuple { [1]: integer, [2]: boolean }

---@type my_tuple
local tuple = {1, true}

--- This works!
local a, b = tuple[1], tuple[2]

--- This gets "integer" for "c", but "unknown" for "d:
local c, d = table.unpack(tuple)
```

### Actual Behaviour

```lua
---@alias my_tuple { [1]: integer, [2]: boolean }

---@type my_tuple
local tuple = {1, true}

--- "c" should be "integer" and "d" "boolean":
local c, d = table.unpack(tuple)
```

### Reproduction steps

1. Define tuple like I did
2. Create such tuple
3. `unpack` to two variables

### Additional Notes

I'm not sure if this is a feature that is even considered, but since I do use unpack sometimes to destructure tuples into their distinct variables, I feel this would be a good feature to have.

### Log File

_No response_

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the issue with the tuple and table.unpack example in the report, then trace the language server's type inference for multiple assignment and unpacked tables. No source files or tests are named; done means the example infers c as integer and d as boolean without regressing existing tuple diagnostics.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.