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

coroutine.wrap has wrong return type / leads to false diagnostic warnings

Open mfussenegger opened this issue 3 years ago • 0 comments

How are you using the lua-language-server?

NeoVim

Which OS are you using?

Linux

What is the issue affecting?

Diagnostics/Syntax Checking

Expected Behaviour

No warnings reported

Actual Behaviour

Language server publishes diagnostics with a warning with message "This function expects a maximum of 0 argument(s) but instead it is receiving 1."

Reproduction steps

Create a lua file with:

local f = coroutine.wrap(function()
  local x = coroutine.yield()
  print(x)
end)
f()
f(20)

It reports a warning for f(20) stating that the function doesn't take any arguments.

It looks like coroutine.wrap has the wrong return type:

function coroutine.wrap(f: fun())
  -> fun()
─────────────────────────────────────────────────────────────────────────
Creates a new coroutine, with body `f`; `f` must be a function. Returns a
function that resumes the coroutine each time it is called.

[View documents](http://www.lua.org/manual/5.1/manual.html#pdf-coroutine.wrap)

From the reference:

Creates a new coroutine, with body f. f must be a Lua function. Returns a function that resumes the coroutine each time it is called. Any arguments passed to the function behave as the extra arguments to resume. Returns the same values returned by resume, except the first boolean. In case of error, propagates the error.

The important part is this:

Any arguments passed to the function behave as the extra arguments to resume

The same is the case in Lua 5.4: http://www.lua.org/manual/5.4/manual.html#6.2

Additional Notes

No response

Log File

No response

mfussenegger avatar Aug 11 '22 11:08 mfussenegger