Skip to content

Proposal consider vararg returns as forced optional #3036

@TIMONz1535

Description

@TIMONz1535

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions