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)
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Lua
- Estrelas
- 4.4k
- Forks
- 442
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
### 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_
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece pelo Lua e pelas anotações de tipo na reprodução e, em seguida, rastreie o caminho de verificação de tipos que produz o diagnóstico de campos ausentes para parâmetros de união e sobrecarga. Está concluído quando tabelas genéricas são aceitas para todas as três chamadas sem reportar TestClass.TestField como ausente; nenhum arquivo-fonte ou teste é nomeado na issue.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- lua
- Domínio
- devtools
- Tipo de issue
- Bug
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 35/100