LuaLS / LuaLS/lua-language-server
Generic type inference breaks for class-style tables with indexed fields (---@class list<T>: { [integer]: T })
未關閉
還沒有人認領這個 Issue。
- 主要語言
- Lua
- 星號
- 4.4k
- 分支
- 442
- PR 合併指標
- 30 天內沒有已合併 PR
描述
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
Windows
What is the issue affecting?
Type Checking
Expected Behaviour
---@type string[]
local testA = { }
local testB = { 1, 2, 3 }
local testAA = List(testA)
local testBB = List(testB)
local vAA1 = testAA[1] -- expected: string
local vBB1 = testBB[1] -- expected: integer
local vAA2 = testAA:at(1) -- expected: string
local vBB2 = testBB:at(1) -- expected: integer
---@type list<number>
local testCC = List {}
-- newList -> expected: list<number>
local newList = testCC:whereList(function(a) return a == 0 end)
-- front -> expected: number
local front = newList:front()
Actual Behaviour
---@type string[]
local testA = { }
local testB = { 1, 2, 3 }
local testAA = List(testA)
local testBB = List(testB)
local vAA1 = testAA[1] -- actual: string|<T>
local vBB1 = testBB[1] -- actual: string|<T>
local vAA2 = testAA:at(1) -- actual: unknown
local vBB2 = testBB:at(1) -- actual: unknown
---@type list<number>
local testCC = List {}
-- newList -> actual: list<<T>>
local newList = testCC:whereList(function(a) return a == 0 end)
-- front -> actual: unknown
local front = newList:front()
Reproduction steps
---@meta
---@generic T
---@param t T[]
---@return list<T>
function List(t)
return listlib:new(t);
end
---@class list<T>: { [integer] : T }
listlib = {}
---@generic T
---@param t T[]
---@return list<T>
function listlib:new(t) end
---@generic T
---@param self list<T>
---@param index integer
---@return T
function listlib:at(index) end
---@generic T
---@param self list<T>
---@return T
function listlib:front() end
---@generic T
---@param self list<T>
---@param predicate fun(a: T): boolean
---@return list<T>
function listlib:whereList(predicate) end
---@type string[]
local testA = { }
local testB = { 1, 2, 3 }
local testAA = List(testA)
local testBB = List(testB)
local vAA1 = testAA[1] -- expected: string, actual: string|<T>
local vBB1 = testBB[1] -- expected: integer, actual: string|<T>
local vAA2 = testAA:at(1) -- expected: string, actual: unknown
local vBB2 = testBB:at(1) -- expected: integer, actual: unknown
---@type list<number>
local testCC = List {}
-- newList -> expected: list<number>, actual: list<<T>>
-- front -> expected: number ,actual: unknown
local newList = testCC:whereList(function(a) return a == 0 end)
local front = newList:front()
Additional Notes
No response
Log File
No response
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
在 Visual Studio Code extension 中重現最小的 Lua 範例,從通用的 List/listlib 宣告和類別風格的列表註解開始。追蹤 indexed access、at、whereList 和 front 的型別推斷。完成的標準是推斷出的型別符合預期的 string、integer 和 number 結果,而不是 unknown 或未解析的泛型型別。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- lua
- 領域
- devtools
- Issue 類型
- 缺陷
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 48/100