LuaLS / LuaLS/lua-language-server

Proposal consider vararg returns as forced optional

Offen
#3,036 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?

Diagnostics/Syntax Checking

### Expected Behaviour

I suggest consider **vararg returns** as **optional** (can be `nil`) because no one guarantees that they will be filled in. The same goes for arguments, despite the fact that their type can also be optional or nilable.

If we return at least something, but we don't know the quantity, then the first argument won't be vararg - `any, any ...`.

Thus after that we do not need to additionally specify that the vararg returns is optional.

```lua
---@param a string
function test(a) end

---@param ... string
---@return string ...
function f(...) end
local a, b, c = f() --no warn
local a, b, c = f("1")

test(a) --no warn, expected optinal cannot match

---@param ... string?
---@return string? ...
function f(...) end
local a, b, c = f() --no warn
local a, b, c = f("1")

test(a) --warn optinal cannot match

---@param ... string|nil
---@return string|nil ...
function f(...) end
local a, b, c = f() --no warn
local a, b, c = f("1")

test(a) --warn nil cannot match
```

### Actual Behaviour

Vararg arguments are optional, but vararg returns are not.

![изображение](https://github.com/user-attachments/assets/e910ce6b-c4d3-4b7e-8a44-83e8725c4bb4)

### Reproduction steps

1. Make vararg return of some existing type.
2. It is guaranteed to be infinite - not optional or nil.

### 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 mit der Behandlung von Diagnosen und Typinferenz des Lua language server für vararg-Argumente und -Rückgabewerte und verwende die Reproduktionsschritte und Beispiele als Verhaltensleitfaden. Überprüfe, dass vararg-Rückgabewerte gegebenenfalls als optional oder nilable behandelt werden, während die angegebenen Aufrufe die erwarteten Warnungen beziehungsweise keine Warnungen erzeugen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
lua
Bereich
devtools
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 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.