LuaLS / LuaLS/lua-language-server

Index an enum-value table bug

Open
#2,921 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?

Visual Studio Code Extension (sumneko.lua)

### Which OS are you using?

Windows

### What is the issue affecting?

Type Checking

### Expected Behaviour

expected the value type of mapping when index

### Actual Behaviour

got an unknown

### Reproduction steps

```lua
---@enum(key) AttrName
local o = {
['hp_max'] = true,
}
local map = {
['hp_max'] = 114514,
}
---@param t table
local function test(t)
--[[
Usage 1: correct
]]
local a = 'hp_max'
local b = t[a] -- expected: number, got: number
print(b)

--[[
Usage 2: incorrect
]]
local c = t['hp_max'] -- expected: number, got: unknown
print(c)

--[[
Usage 3: correct
]]
local d = "hp_grow"
local e = t[d] -- expected: unknown, got: unknown
print(e)
end
test(map)
```

### Additional Notes

_No response_

### 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

Reproduce the report in the LuaLS Visual Studio Code extension on Windows using the supplied Lua snippet and inspect the type-checking path for enum-key table indexing. Compare the diagnostics for the three usages, especially the literal 'hp_max' index. Done means the reported types match the expectations in the reproduction.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
compilers, devtools
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.