LuaLS / LuaLS/lua-language-server

Question mark optional syntax not supported in fun() declarations

Offen
#2,385 1 Kommentar 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

Optional value to actually be optional

Actual Behaviour

It's not optional.
image
This code block should show as Human? and throw warnings for not checking nil. If I manually annotate with ---@param man Human? this works as expected.

The class in question:

---@class Command
---@field info string What the command does.
---@field usage string? How to use the command.
---@field alias string[]? Aliases of the command.
---@field canCall (fun(player: Player): boolean)? Function which checks whether a player can call this command.
---@field call fun(player: Player, human: Human?, args: string[]) Calls the command.
---@field autoComplete fun(args: string[])? Function which manipulates arguments when pressing tab in the terminal.
---@field cooldownTime number? How many seconds a player has to wait before using the command again.

I have also tried with human?: Human and human?: Human? but neither way works.

Reproduction steps
  1. Create class with a field with a short form function declaration with an optional value parameter
  2. Attempt to create object of class with that field,
  3. Parameter correctly types, except as not optional.
Additional Notes

No response

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

Beginne damit, das Klassenfeld-Beispiel in der Visual Studio Code extension zu reproduzieren, wobei du dich auf die Kurzform der Funktionsdeklaration mit einem nullable Human-Parameter konzentrierst. Vergleiche es mit dem manuell annotierten Fall ---@param man Human?; abgeschlossen ist es, wenn der Parameter als optional inferiert wird und Nil-Prüfungswarnungen wie beschrieben erscheinen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
lua, vscode
Bereich
devtools
Issue-Typ
Bug
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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