Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal consider vararg returns as forced optional #3036

Open
TIMONz1535 opened this issue Jan 11, 2025 · 0 comments
Open

Proposal consider vararg returns as forced optional #3036

TIMONz1535 opened this issue Jan 11, 2025 · 0 comments

Comments

@TIMONz1535
Copy link
Contributor

TIMONz1535 commented Jan 11, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant