-
-
Notifications
You must be signed in to change notification settings - Fork 403
Description
How are you using the lua-language-server?
NeoVim
Which OS are you using?
Windows
What is the issue affecting?
Annotations, Type Checking
Expected Behaviour
The return type of string.match should be string|integer? and the return type of string.gmatch, should be a function which returns multiple string|integer ...
Actual Behaviour
The return type of string.match is any and the return type of string.gmatch is (fun(): string, ...), which causes #2487
See
lua-language-server/meta/template/string.lua
Lines 90 to 96 in 0187ddf
| ---#DES 'string.match' | |
| ---@param s string|number | |
| ---@param pattern string|number | |
| ---@param init? integer | |
| ---@return any ... | |
| ---@nodiscard | |
| function string.match(s, pattern, init) end |
and
lua-language-server/meta/template/string.lua
Lines 54 to 67 in 0187ddf
| ---#DES 'string.gmatch' | |
| ---#if VERSION <= 5.3 then | |
| ---@param s string|number | |
| ---@param pattern string|number | |
| ---@return fun():string, ... | |
| ---@nodiscard | |
| function string.gmatch(s, pattern) end | |
| ---#else | |
| ---@param s string|number | |
| ---@param pattern string|number | |
| ---@param init? integer | |
| ---@return fun():string, ... | |
| function string.gmatch(s, pattern, init) end | |
| ---#end |
Reproduction steps
Try casting the first for loop variable from a :gmatch() into an integer (---@cast x integer), it throws an invalid warning; see no completion of return values from a :match().
Additional Notes
It seems to be currently not possible to specify types for ... return types using the fun() syntax. As a workaround at least define the first return value as string|integer instead of string.
Log File
No response