LuaLS / LuaLS/lua-language-server

False negative for param-type-mismatch when using a variable as argument

Abierto
#2,734 0 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

### Expected Behaviour

```lua
---@class (exact) Foo
---@field FooField integer
local Foo

---@param FooParam Foo
local function test(FooParam) end

local x = {z = 1}
test(x)

test({z = 1})
```

In the example above, Lua LS should report a param-type-mismatch diagnostic for `test(x)`. It has enough information to know that x cannot be of type Foo, at the very least because it is missing `FooField`.
We see that test({z=1}) correctly reports the param-type-mismatch diagnostic.

### Actual Behaviour

No error is reported.
![image](https://github.com/LuaLS/lua-language-server/assets/36710691/5bd6c68a-21ab-4235-b4e3-2f5c7f9a87de)

### Reproduction steps

In any editor with Lua LS installed, write the provided code. Observe that there are no squiggles reported.

### Additional Notes

I would say this is a pretty serious bug. I would have expected Lua LS's type checking to be robust enough to handle checking the types of variables. It seems that all it is doing is checking that the type is a table.

IS this because there is no narrowing of variables once they become tables? This is only done for table literals?

### 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 la reproducción de Lua proporcionada en Lua LS y sigue la ruta de comprobación de tipos para el parámetro pasado a test, comparando el argumento variable con el literal de tabla. Se considera terminado cuando se informa el mismo diagnóstico param-type-mismatch para test(x), incluido el caso de FooField ausente.

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
42/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.