LuaLS / LuaLS/lua-language-server

Generics, inheritance and an overloaded constructor

未關閉
#2,534 0 則留言 1 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 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.

![image](https://github.com/LuaLS/lua-language-server/assets/34756939/e6501b99-d3d3-4ef2-8711-638f0adbefa5)
```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
```

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 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

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。