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)

Abierto
#2,606 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Lenguaje dominante
Lua
Estrellas
4.4k
Forks
442
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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:

---@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

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

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza con Lua y las anotaciones de tipos de la reproducción; después, sigue la ruta de comprobación de tipos que produce el diagnóstico de campos faltantes para los parámetros de unión y sobrecarga. Se considera terminado cuando las tablas genéricas se aceptan para las tres llamadas sin informar de que falta TestClass.TestField; en el issue no se nombran archivos fuente ni tests.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
lua
Área
devtools
Tipo de issue
Error
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.