LuaLS / LuaLS/lua-language-server
Generics, inheritance and an overloaded constructor
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
**VisualStudio Code** on Windows, **lua-language-server v3.7.4** (_Last updated 2024-01-07, 10:29:54_)
The following error occurs only when a **generic** inherits from a type containing an overloaded constructor.

```lua
local e = Entity()
e:get(Transform2)
e:get(Transform)
```
The only difference between `Transform` and `Transform2` is the overloaded constructor.
I could "workaround" this issue by removing `: ComponentBase` from the function `Entity:get` ... but I want to check whether the given component `type` is valid.
---
Here is the simplified annotation file:
```lua
---@class ComponentBase
---@class Transform: ComponentBase
Transform = {}
---@class Transform2: ComponentBase
---@overload fun(x: number, y: number): Transform2
Transform2 = {}
---@class Entity
---@overload fun(): Entity
Entity = {}
---@generic T: ComponentBase
---@param type T
---@return T
function Entity:get(type) 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 with the simplified annotation file in the issue and reproduce the diagnostic in Visual Studio Code on Windows using lua-language-server v3.7.4. Compare the generic Entity:get calls for Transform and Transform2, then verify that the valid component types are handled consistently without the reported error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100