LuaLS / LuaLS/lua-language-server
Generics, inheritance and an overloaded constructor
還沒有人認領這個 Issue。
- 主要語言
- Lua
- 星號
- 4.4k
- 分支
- 442
- PR 合併指標
- 30 天內沒有已合併 PR
描述
**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
```
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
從 issue 中的簡化註解檔案開始,使用 lua-language-server v3.7.4 在 Windows 上的 Visual Studio Code 中重現該診斷。比較針對 Transform 和 Transform2 的通用 Entity:get 呼叫,然後確認有效的元件型別是否得到一致處理且不會出現所回報的錯誤。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- lua
- 領域
- devtools
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100