LuaLS / LuaLS/lua-language-server

Defining optional globals doesn't trigger nil check warning

Offen
#2,450 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

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

Expected Behaviour

I have some code that runs in different environments that have different global variables available.

For example, environment1 may have a global table C_GameRules available with a function in it. environment2 does not have the global available.

I'm trying to write a meta file that makes this optional nature of this global available:

---@meta

---@type table?
C_GameRules = nil

---@return boolean
function C_GameRules.IsHardcoreActive() end

I've also tried to define a class, no change in behavior

Actual Behaviour

C_GameRules.IsHardcoreActive() does not trigger a need-nil-check warning, but the type of C_GameRules gets shown as table?

Reproduction steps

see above

Additional Notes

i don't want the inner field as nilable, environment 1 has "C_GameRules" as global available and the function is guaranteed to be in there, environment 2 has the global set to nil

Log File

No response

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Reproduziere den Bericht in der Visual Studio Code Extension unter Verwendung der gezeigten Lua-Meta-Dateideklaration und überprüfe die Typprüfungsdiagnosen für C_GameRules.IsHardcoreActive(). Erledigt ist die Aufgabe, wenn ein optionales globales Element eine Nil-Prüfungswarnung erzeugt, während seine innere Funktion weiterhin nicht nil-fähig bleibt.

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

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.