LuaLS / LuaLS/lua-language-server

[Bug] Union when combine table with classified type. Attributes of table are hidden.

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

还没有人认领这个 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

```lua
local data = {}
function data:set(k, v)
rawset(self, k, v)
end

--- @class Person
local Person = {}
function Person:speak() end

--- @generic T
--- @param t T
--- @return T|Person
function merge(t, p)
-- ...
end

local m = merge(data, Person)
m:set -- Completion should show [set(k, v)] 应该提示 set(k,v),对应 data:set(k,v)
```

### Actual Behaviour

```lua
local data = {}
function data:set()
end

--- @class Person
local Person = {}
function Person:speak() end

--- @generic T
--- @param t T
--- @return T|Person
function merge(t, p)
-- ...
end

local m = merge(data, Person)
m:set -- doesn't complete this method, 没显示,只有一个单纯的文本补全
```

But .... 但是... 你换成 {} 而不去声明 `@class Person` 倒是会有的

```lua
local data = {}
function data:set()
end

local Person = {}
function Person:speak() end

--- @generic T
--- @param t T
--- @return T|{speak: function} !!!!! See here !!! 看这里,换成纯粹的 table 到会有
function merge(t, p)
-- ...
end

local m = merge(data, Person)
m:set -- Completion is right and show [set(k,v)],补全正常显示
```

I guess the `@class Person` hides the origin type.

我认为 `@class Person` 把原本的 data 表 属性都给给覆盖掉了。

而且还有个诡异现象,如果 data 给一些 默认值:

`local data = {value = 123}`

不管哪种方式 都能把 默认属性 给补出来。

这很明显这个 luals 的 union 组合有 bug!

### Reproduction steps

See obove

### Additional Notes

_No response_

### Log File

_No response_

贡献指南

打开贡献指南

从这里开始

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

调研方向

使用提供的 Lua 示例在 Visual Studio Code 扩展中重现该问题,将包含 @class Person 的 union 与内联表类型进行比较。跟踪查询 m:set 时 merge 结果的类型检查和 completion 处理。完成标准是 completion 包含 data:set,同时保留 Person 的成员(例如 speak)。

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

评估

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

把新 issue 发到你的邮箱

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