lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

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

Open jakitliang opened this issue 1 year ago • 0 comments

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

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

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 倒是会有的

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

jakitliang avatar Nov 14 '23 20:11 jakitliang