LuaLS / LuaLS/lua-language-server
Cannot inherit generic classes (including tables)
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
Hello, I apologize for bringing yet another generics issue as I know it takes time for it to be made solid... Thanks for looking into my problem. I use the following code to extend the `number[]` class, but then the elements are not marked as numbers for a non literal object.
```lua
---@class NumberTable: number[]
---@param t NumberTable
---@return number|nil
function FirstElement(t)
local n = t[1] -- marked as unknown
return n
end
---@param t number[]
---@return number|nil
function FirstElementBis(t)
local n = t[1] -- marked as number
return n
end
```
I would expect `t[1]` to be marked as `number`. I also tried replacing `number[]` with `table` and `table` without success. Thank you!
(I use LuaLS on Neovim on Linux)
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 issue in LuaLS with the provided NumberTable and FirstElement annotations, using Neovim on Linux as described. Compare the inferred type of t[1] with the direct number[] case and the table variants. Done means inherited generic and table annotations consistently identify the element as number.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua, neovim
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100