Skip to content

Functions with fewer arguments should be accepted as a param/field for functions with more arguments #1692

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

Closed
figsoda opened this issue Nov 12, 2022 · 2 comments
Labels
bug Something isn't working feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats)

Comments

@figsoda
Copy link

figsoda commented Nov 12, 2022

How are you using the lua-language-server?

NeoVim

Which OS are you using?

Linux

What is the issue affecting?

Type Checking

Expected Behaviour

--- @param f fun(a: number)
local function test(f)
  f(42)
end

this should work

test(function() end)

Actual Behaviour

this doesn't work: This function requires 1 argument(s) but instead it is receiving 0.

test(function() end)

this works, even though they are equivalent

test(function(_) end)

Reproduction steps

--- @param f fun(a: number)
local function test(f)
  f(42)
end

test(function() end)

Additional Notes

The same should apply to @field and maybe @type as well

Log File

No response

@carsakiller carsakiller added question User has a question feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats) labels Nov 12, 2022
@carsakiller
Copy link
Collaborator

Hello 👋

Change your annotation to the following and your issue should be resolved:

--- @param f fun(a?: number)
local function test(f)
  f(42)
end

I added a ? after the a param. This tells the server that it is optional.

test(function() end)

this works, even though they are equivalent

test(function(_) end)

These two are not equivalent. The first one is passing nothing, the second one is passing a "throwaway variable" which is not nothing, but has no real meaning when it comes to the execution of the code.

@sumneko sumneko added enhancement New feature or request and removed question User has a question labels Nov 12, 2022
@sumneko
Copy link
Collaborator

sumneko commented Nov 12, 2022

I added a ? after the a param. This tells the server that it is optional.

This will cause user to check nil when using this parameter.

@sumneko sumneko added bug Something isn't working and removed enhancement New feature or request labels Nov 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feat/LuaCats Annotations Related to Lua Language Server Annotations (LuaCats)
Projects
None yet
Development

No branches or pull requests

3 participants