LuaLS / LuaLS/lua-language-server
[Bug] Union when combine table with classified type. Attributes of table are hidden.
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 4.4k
- Forks
- 442
- PR merge metrics
- No merged PRs in 30d
Description
### 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_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue in the Visual Studio Code extension using the provided Lua examples, comparing the union with @class Person against the inline table type. Trace type checking and completion handling for the result of merge when m:set is queried. Done means completion includes data:set while retaining Person members such as speak.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100