LuaLS / LuaLS/lua-language-server
Returning generics with `T<X, Y>`
还没有人认领这个 Issue。
- 主要语言
- Lua
- 星标
- 4.4k
- 派生
- 442
- PR 合并指标
- 30 天内没有已合并 PR
描述
Below, I have a generic list that uses fluid interface to return itself for some methods:
```lua
--- @class List
local List = {}
--- @generic T : List, V, _
--- @param self T
--- @param value V # Element value to insert
--- @return T # Returning itself (a generic)
function List:insert(value)
return self -- Returning itself (a generic)
end
-- test
---@type List
local mylist
local testingType = mylist:insert(1)
-- ^ Testing type is not `List` but literally `T`
```

**Expected behavior**
testingType is of type `List`
I am thinking that this case could be something to look at for the 3.0 update.
(Edit: perfect #1000th issue...)
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
payload 未指出源文件或测试。首先重现提供的 List:insert 示例,并将推断出的类型与预期的 List 进行比较;然后跟踪泛型返回类型推断,并添加一个回归测试,确认结果不再是字面量 T。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100