LuaLS / LuaLS/lua-language-server

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

Aperta
#2,414 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Lua
Stelle
4.4k
Fork
442
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Riproducete il problema nell’estensione di Visual Studio Code utilizzando gli esempi Lua forniti e confrontate l’unione con @class Person con il tipo di tabella inline. Tracciate il controllo dei tipi e la gestione del completamento per il risultato di merge quando viene interrogato m:set. Il lavoro è completato quando il completamento include data:set mantenendo al contempo i membri di Person come speak.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
lua
Ambito
devtools
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
38/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.