LuaLS / LuaLS/lua-language-server
Initializing a table doesn't satisfied `need-check-nil`
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
Issue Description
Hi!
I have a code that looks something like this:
---@param t? table
function api.f(t)
t = type(t) == "table" and t or {}
t.x = t.x or {} --warning is raised but t can never be nil here because it is set to {} if it was but diagnostics fail to see that
--etc.
end
Nil checks are not required here because t should never be nil, the preceding lines redefines it as an empty table if it was nil or invalid so the reference should always exist when trying to check if x exists within the table.
I have seen similar reports but I'm not sure if this exact case has been reported or not. I couldn't find a match or I failed to recognize it.
Additional Notes
No response
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
Non sono indicati file sorgente o test. Inizia riproducendo l’esempio Lua e seguendo la diagnostica del controllo nil per l’avviso need-check-nil; il lavoro è completato quando l’avviso non viene segnalato per t.x dopo che t è stato normalizzato a una tabella.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- lua
- Ambito
- devtools
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 42/100