LuaLS / LuaLS/lua-language-server
`generic` inheritance does not work
未关闭
还没有人认领这个 Issue。
enhancement
feat/generic
feat/LuaCats Annotations
- 主要语言
- Lua
- 星标
- 4.4k
- 派生
- 442
- PR 合并指标
- 30 天内没有已合并 PR
描述
The second case
Core = {};
---@class Rotation
---@field Enabled boolean
local Rotation = {}
function Rotation:OnLoad() end
function Rotation:OnUnload() end
---@class RotationEngine
Core.RotationEngine = {}
---@generic T
---@param name `T`
---@return T|Rotation rotation
function Core.RotationEngine.AddRotation(name) end
---@class MyRotation
---@field testfield table
local MyRotation = {};
function MyRotation:Test() end
local rotation = Core.RotationEngine.AddRotation("MyRotation");
---@param self MyRotation
---@return boolean
local function myFunc(self) end
local a = myFunc(rotation);
In the first case, in the MyRotation class, we seek methods of the Rotation class,

but also an error Cannot assign MyRotation|Rotation to parameter MyRotation.Lua Diagnostics.(param-type-mismatch)

The second case
Core = {};
---@class Rotation
---@field Enabled boolean
local Rotation = {}
function Rotation:OnLoad() end
function Rotation:OnUnload() end
---@class RotationEngine
Core.RotationEngine = {}
---@generic T: Rotation
---@param name `T`
---@return T rotation
function Core.RotationEngine.AddRotation(name) end
---@class MyRotation
---@field testfield table
local MyRotation = {};
function MyRotation:Test() end
local rotation = Core.RotationEngine.AddRotation("MyRotation");
---@param self MyRotation
---@return boolean
local function myFunc(self) end
local a = myFunc(rotation);
In the second case there is no inheritance

and there is no error either

贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先重现 issue 中的两个 Lua 代码片段,并比较 rotation 的推断类型、方法补全和诊断信息。跟踪 AddRotation 涉及的泛型返回类型推断和类继承处理。完成的标准是预期继承的成员可用,并且错误的 MyRotation|Rotation 类型不匹配得到解决,同时不丢失第二种情况的行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- lua
- 领域
- devtools
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100