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

Method call using named arguments has missing-parameter false positives #2671

Closed
Jessidhia opened this issue May 17, 2024 · 2 comments
Closed

Comments

@Jessidhia
Copy link

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

MacOS

What is the issue affecting?

Type Checking

Expected Behaviour

No error, or at least a different, more appropriate error if applicable.

Actual Behaviour

This function requires 3 argument(s) but instead it is receiving 2. Lua Diagnostics.(missing-parameter)

Reproduction steps

---@class frame
local frame = {}

---forward declaration
---@param title string
---@param args table<string | number, string>
---@return string
---@nodiscard
function frame:expandTemplate(title, args) end

---@param frame frame
---@param template string
---@param cargoRow table<string, string>
function renderRow(frame, template, cargoRow)
  -- "This function requires 3 argument(s) but instead it is receiving 2."
  return frame:expandTemplate { title = template, args = cargoRow }
  -- writing "return frame:expandTemplate(template, cargoRow)" instead is fine
end

Additional Notes

No response

Log File

No response

@emmericp
Copy link
Contributor

emmericp commented May 19, 2024

This is WAI, Lua doesn't have named arguments, you are calling the function with a table as the title parameter and nothing in the args parameter.

The actual function you are using may be supporting this by checking the type of the first argument. In this case your "forward declaration" is wrong and you probably want an additional @overload annotation that indicates this.

@Jessidhia
Copy link
Author

Looks like I got tricked by the wording of the documentation and wrote the wrong forward declaration 😅

(Especially confusing on the next function, as it further implies that it's just something that's part of the language)

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

2 participants