LuaLS / LuaLS/lua-language-server

Generics, inheritance and an overloaded constructor

未关闭
#2,534 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

主要语言
Lua
星标
4.4k
派生
442
PR 合并指标
30 天内没有已合并 PR

描述

VisualStudio Code on Windows, lua-language-server v3.7.4 (Last updated 2024-01-07, 10:29:54)

The following error occurs only when a generic inherits from a type containing an overloaded constructor.

image

local e = Entity()
e:get(Transform2)
e:get(Transform)

The only difference between Transform and Transform2 is the overloaded constructor.

I could "workaround" this issue by removing : ComponentBase from the function Entity:get ... but I want to check whether the given component type is valid.


Here is the simplified annotation file:

---@class ComponentBase

---@class Transform: ComponentBase
Transform = {}

---@class Transform2: ComponentBase
---@overload fun(x: number, y: number): Transform2
Transform2 = {}

---@class Entity
---@overload fun(): Entity
Entity = {}

---@generic T: ComponentBase
---@param type T
---@return T
function Entity:get(type) end

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 issue 中的简化注解文件开始,使用 lua-language-server v3.7.4 在 Windows 上的 Visual Studio Code 中重现该诊断。比较针对 Transform 和 Transform2 的通用 Entity:get 调用,然后验证有效的组件类型是否得到一致处理且不会出现所报告的错误。

由索引模型根据 Issue 内容生成。

评估

技术栈
lua
领域
devtools
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。