LuaLS / LuaLS/lua-language-server

Cannot inherit generic classes (including tables)

Open
#3,271 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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.