-
-
Notifications
You must be signed in to change notification settings - Fork 386
Closed
Labels
questionUser has a questionUser has a question
Description
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?
Annotations, Type Checking
Expected Behaviour
I expect the following code to be accepted (as it was in the past):
---@param str string
---@param multiple? boolean If `true`, all matches are returned as a list
---@return string[] results Single or multiple matches
---@overload fun(str: string): string
local function someFunction(str, multiple)
if multiple == true then
return { "a match" }
end
return "a match"
end
local result = someFunction("some string")
print(result:match("some regex"))There should be no warning from the call to result:match().
Actual Behaviour
LLS isn't able to determine that the overloaded function definition needs to be used for this call. So it sees both possible return values (string[] and string). Of course string[] doesn't have a match method, so the following warning is emitted:
Cannot assign `string|string[]` to parameter `string|number`.
- `string[]` cannot match `string|number`
- `string[]` cannot match any subtypes in `string|number`
- Type `string[]` cannot match `number`
- Type `string[]` cannot match `string`
Reproduction steps
Try the example above with the latest VS Code extension
Additional Notes
Using version 3.6.18. It has worked in a previous version.
Log File
No response
Metadata
Metadata
Assignees
Labels
questionUser has a questionUser has a question
