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
| ---#DES 'string.match' |
| ---@paramsstring|number |
| ---@parampatternstring|number |
| ---@paraminit?integer |
| ---@returnany ... |
| ---@nodiscard |
| functionstring.match(s, pattern, init) end |
and
| ---#DES 'string.gmatch' |
| ---#if VERSION <= 5.3 then |
| ---@paramsstring|number |
| ---@parampatternstring|number |
| ---@returnfun():string, ... |
| ---@nodiscard |
| functionstring.gmatch(s, pattern) end |
| ---#else |
| ---@paramsstring|number |
| ---@parampatternstring|number |
| ---@paraminit?integer |
| ---@returnfun():string, ... |
| functionstring.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
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.matchshould bestring|integer?and the return type ofstring.gmatch, should be a function which returns multiplestring|integer ...Actual Behaviour
The return type of
string.matchisanyand the return type ofstring.gmatchis(fun(): string, ...), which causes #2487See
lua-language-server/meta/template/string.lua
Lines 90 to 96 in 0187ddf
and
lua-language-server/meta/template/string.lua
Lines 54 to 67 in 0187ddf
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 thefun()syntax. As a workaround at least define the first return value asstring|integerinstead ofstring.Log File
No response