LuaLS / LuaLS/lua-language-server

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

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

```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_

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

Inizia con la riproduzione Lua fornita in Lua LS e segui il percorso del controllo dei tipi per il parametro passato a test, confrontando l'argomento variabile con il literal di tabella. Il lavoro è completato quando viene riportata la stessa diagnostica param-type-mismatch per test(x), incluso il caso di FooField mancante.

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

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.