LuaLS / LuaLS/lua-language-server
Index an enum-value table bug
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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