LuaLS / LuaLS/lua-language-server
Problem with generics
還沒有人認領這個 Issue。
- 主要語言
- Lua
- 星號
- 4.4k
- 分支
- 442
- PR 合併指標
- 30 天內沒有已合併 PR
描述
I have reported a similar problem before and I understand that it is not simple, but if you solve it, I will be crazy happy!
I'm working on an OOP library and here's a truncated example of the constructor it uses:
---@generic T
---@param t1 T
---@param t2 T
---@return T
function new(t1, t2) end
The first table here is the class from which the instance will inherit, and the second is the additional settings that will be substituted to the instance. So all tables has the same type.
When I call this constructor, the generics work almost correctly - the result of this function has the same type as any argument:
---@class Example1
---@field e1a string
---@field e1b string
local Example1 = {}
---@class Example2
---@field e2a string
---@field e2b string
local Example2 = {}
local e = new(Example1, {}) -- e is Example1
local e = new(Example2, {}) -- e is Example2
local e = new({}, Example1) -- e is Example1
local e = new({}, Example2) -- e is Example2
But the problem is that when I start typing a text between the curly braces in the example above, I get no hints about the class fields. Maybe I'm describing generics wrong? Do you have any idea? Thanks!
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
未指定原始檔案或測試。請在 Lua language server 中重現泛型建構函式範例,並檢查當第一個參數為 Example1 或 Example2 時,如何在空白表格引數內推斷補全。完成的標準是:在這些表格常值中建議相關的類別欄位,同時保留現有的推斷結果型別。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- lua
- 領域
- devtools
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100