LuaLS / LuaLS/lua-language-server
Incorrect field type calculation when field name in variable
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) v3.11.0
### Which OS are you using?
Linux
### What is the issue affecting?
Type Checking
### Reproduction steps
```lua
---@diagnostic disable: unused-local
---@class Class
local Class = { __type = "Class" }
local field = "some_string" -- field: string = "some_string"
do
local c = {} ---@type Class
-- OK
local f1 = c["some_string"] -- f1: unknown
local f2 = c[field] -- f2: unknown
end
function Class:f()
-- OK
local f1 = self["some_string"] -- f1: unknown
-- BUT
local f2 = self[field] -- f2: string = "Class"
end
do
-- OK
local f1 = Class["some_string"] -- f1: unknown
-- BUT
local f2 = Class[field] -- f2: string = "Class"
end
```
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
Start by reproducing the type-checking discrepancy in the Lua language server with the code sample, comparing literal indexing with indexing through the `field` variable. Trace the field-type inference entry point and add a regression test for the shown cases; done means variable-based indexing no longer reports `Class` where literal indexing reports `unknown`.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100