-
-
Notifications
You must be signed in to change notification settings - Fork 391
Open
Description
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 matchActual Behaviour
Vararg arguments are optional, but vararg returns are not.
Reproduction steps
- Make vararg return of some existing type.
- It is guaranteed to be infinite - not optional or nil.
Additional Notes
No response
Log File
No response
Metadata
Metadata
Assignees
Labels
No labels
