LuaLS / LuaLS/lua-language-server
Union table|class doesn't accept a generic table and only accepts a class instance (causing false missing-fields diagnostic)
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, Diagnostics/Syntax Checking
### Expected Behaviour
When a function is declared as accepting both `table` and a custom class type, it should accept getting passed a generic table.
### Actual Behaviour
LLS insists on a table matching the class being passed (with all the fields set) and reports the missing-fields diagnostic when passing a generic table.
### Reproduction steps
LLS definition file contains the following:
```lua
---@meta
---@class TestClass
---@field TestField number A test field in test class
TestClass = {}
-- TestFunction1
---@param generic_table_or_testclass_instance table|TestClass
function TestFunction1(generic_table_or_testclass_instance) end
-- TestFunction2
---@param generic_table table
---@param testclass_instance TestClass
---@overload fun(generic_table: table)
---@overload fun(testclass_instance: TestClass)
function TestFunction2(generic_table, testclass_instance) end
-- TestFunction3
---@param generic_table table
function TestFunction3(generic_table) end
-- TestFunction3
---@param testclass_instance TestClass
function TestFunction3(testclass_instance) end
```
And then a lua code file contains a call to either test function like
```lua
TestFunction1({1,2,3})
TestFunction2({1,2,3})
TestFunction3({1,2,3})
```
LLS reports `Missing required fields in type ``TestClass``: ``TestField`` Lua Diagnostics.(missing-fields)` for all 3 calls. Instead it should accept the table as input parameter for the 3 functions.
### Additional Notes
_No response_
### Log File
_No response_
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia da Lua e dalle annotazioni di tipo nella riproduzione, quindi segui il percorso di controllo dei tipi che produce la diagnostica dei campi mancanti per i parametri di unione e overload. Il lavoro è completato quando le tabelle generiche vengono accettate per tutte e tre le chiamate senza segnalare TestClass.TestField come mancante; nell’issue non vengono indicati file sorgente o test.
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
- 35/100