LuaLS / LuaLS/lua-language-server
string|nil passed to string parameter not flagged as error with strict settings
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?
Command Line
### Which OS are you using?
Linux
### What is the issue affecting?
Type Checking
### Expected Behaviour
With the following config (see below), I expect Lua Language Server to report a type mismatch when passing a `string|nil` value to a function that expects a non-optional string parameter.
Specifically, this line should raise a diagnostic:
```
test_func(params.ip) -- where params.ip is string|nil, but test_func expects string
```
### Actual Behaviour
No error is reported by LLS, neither in VS Code nor when using the CLI with `--check`.
### Reproduction steps
1. Save this code in a `.lua` file:
```
---@class TestParams
---@field ip string | nil
---@param ip string
---@return string
local function test_func(ip)
return ip
end
---@type TestParams
local params = { ip = nil }
test_func(params.ip)
```
2. Use the following `lua-language-server config` (`.luarc.json` or through your client):
```
{
"runtime": {
"version": "Lua 5.1"
},
"diagnostics": {
"enable": true,
"disable": [],
"groupFileStatus": {
"ambiguity": "Any",
"await": "Any",
"codestyle": "Any",
"duplicate": "Any",
"global": "Any",
"luadoc": "Any",
"redefined": "Any",
"strict": "Any",
"strong": "Any",
"type-check": "Any",
"unbalanced": "Any",
"unused": "Any"
},
"groupSeverity": {
"ambiguity": "Error",
"await": "Error",
"codestyle": "Error",
"duplicate": "Error",
"global": "Error",
"luadoc": "Error",
"redefined": "Error",
"strict": "Error",
"strong": "Error",
"type-check": "Error",
"unbalanced": "Error",
"unused": "Error"
}
},
"type": {
"weakNilCheck": false
}
}
```
3. Run the CLI:
```
lua-language-server-3.15.0-linux-x64/bin/lua-language-server --check your_file.lua
```
Or use VS Code extension.
### Additional Notes
_No response_
### Log File
```
Diagnosis completed, no problems found
```
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 con il riproduttore Lua fornito e `.luarc.json`, quindi esegui il comando documentato `lua-language-server --check` per confermare la diagnostica mancante. Traccia il percorso del controllo dei tipi per gli argomenti delle funzioni e aggiungi la copertura di regressione; il lavoro è completato quando l'argomento `string|nil` viene segnalato come incompatibile con il parametro `string` richiesto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- lua
- Ambito
- tooling
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100