LuaLS / LuaLS/lua-language-server
Generic type inference breaks for class-style tables with indexed fields (---@class list<T>: { [integer]: T })
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Lua
- Star
- 4.4k
- Fork
- 442
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
### 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
```lua
---@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
local testCC = List {}
-- newList -> expected: list
local newList = testCC:whereList(function(a) return a == 0 end)
-- front -> expected: number
local front = newList:front()
```
### Actual Behaviour
```lua
---@type string[]
local testA = { }
local testB = { 1, 2, 3 }
local testAA = List(testA)
local testBB = List(testB)
local vAA1 = testAA[1] -- actual: string|
local vBB1 = testBB[1] -- actual: string|
local vAA2 = testAA:at(1) -- actual: unknown
local vBB2 = testBB:at(1) -- actual: unknown
---@type list
local testCC = List {}
-- newList -> actual: list<>
local newList = testCC:whereList(function(a) return a == 0 end)
-- front -> actual: unknown
local front = newList:front()
```
### Reproduction steps
```lua
---@meta
---@generic T
---@param t T[]
---@return list
function List(t)
return listlib:new(t);
end
---@class list: { [integer] : T }
listlib = {}
---@generic T
---@param t T[]
---@return list
function listlib:new(t) end
---@generic T
---@param self list
---@param index integer
---@return T
function listlib:at(index) end
---@generic T
---@param self list
---@return T
function listlib:front() end
---@generic T
---@param self list
---@param predicate fun(a: T): boolean
---@return list
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|
local vBB1 = testBB[1] -- expected: integer, actual: string|
local vAA2 = testAA:at(1) -- expected: string, actual: unknown
local vBB2 = testBB:at(1) -- expected: integer, actual: unknown
---@type list
local testCC = List {}
-- newList -> expected: list, actual: list<>
-- 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_
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Tái hiện ví dụ Lua tối thiểu trong Visual Studio Code extension, bắt đầu với các khai báo List/listlib tổng quát và chú thích danh sách theo kiểu lớp. Theo dõi suy luận kiểu cho indexed access, at, whereList và front. Hoàn tất khi các kiểu được suy luận khớp với các kết quả string, integer và number mong đợi thay vì là unknown hoặc các kiểu generic chưa được giải quyết.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- lua
- Lĩnh vực
- devtools
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 48/100