LuaLS / LuaLS/lua-language-server
Missing diagnostic when passing nil-able fields to pairs/ipairs
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Lua
- Sterne
- 4.4k
- Forks
- 442
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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
In the following code, I expect to get param-type mismatch for each of the for loops (with pairs and ipairs) because the variable being iterated can be nil:
---@type string[]?
local x1 = {}
for _ in ipairs(x1) do -- param-type-mismatch: Cannot assign `string[]?` to parameter `<T:table>
break
end
---@type table<string, boolean>?
local y1 = {}
for _ in ipairs(y1) do -- param-type-mismatch: Cannot assign `table<string, boolean>?` to parameter `<T:table>
break
end
---@class Class
---@field x string[]?
---@field y table<string, boolean>?
---@type Class
local x2 = {}
for _ in ipairs(x2.x) do -- Should warn, but it doesn't
break
end
for _ in pairs(x2.y) do -- Should warn, but it doesn't
break
end
Actual Behaviour
The param-type-mismatch diagnostic is only shown for the first two loops (direct variables without nesting/fields), but not when using fields (the third and fourth for loops).
Reproduction steps
Copy the code into a Lua file and observe the diagnostics
Additional Notes
No response
Log File
No response
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Reproduzieren Sie das Problem, indem Sie das bereitgestellte Lua-Beispiel in eine Lua-Datei kopieren und die Diagnosen für direkte Variablen mit denen für verschachtelte Felder vergleichen. Verfolgen Sie den Pfad der Typprüfung, der Argumente von ipairs und pairs verarbeitet, und überprüfen Sie anschließend, dass nullable Felder dieselbe param-type-mismatch-Diagnose wie direkte Variablen erhalten.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- lua
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100