LuaLS / LuaLS/lua-language-server

Array type matches any table

Open
#3,101 0 comments 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?

Linux

### What is the issue affecting?

Type Checking

### Expected Behaviour

When assigning a class/key-value table to a type defined as an array, a diagnostics error should be raised.

### Actual Behaviour

No diagnostics error is raised.

### Reproduction steps

```lua
local dict = {a = 'a'}

---@type number[]
local array = dict
```
Observe that no diagnostics error is raised when assigning `dict` to `array`, which is defined as an array.

### Additional Notes

`lua-langauge-server` should check for the presence of non-integer indices in a table. If there are any, the table should not match the array type.

I believe the present issue is the underlying issue in #1721.

### Version

3.13.6-1

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

The issue names no source file or test. Start by running the provided Lua reproduction with lua-language-server 3.13.6-1 and trace the type-checking path for table-to-array assignment. Done means a diagnostic is reported for a table containing a non-integer key while valid arrays remain accepted.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.