lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

Proposal consider vararg returns as forced optional

Open TIMONz1535 opened this issue 9 months ago • 1 comments

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.

---@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.

изображение

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

TIMONz1535 avatar Jan 11 '25 22:01 TIMONz1535