lua-language-server
lua-language-server copied to clipboard
Cannot type for-loop variable
How are you using the lua-language-server?
NeoVim
Which OS are you using?
Linux
What is the issue affecting?
Type Checking, Diagnostics/Syntax Checking
Expected Behaviour
The variables s and r are typed according to the @type annotation.
Actual Behaviour
In the following code snippet I cannot type the for loop variables s and r using the @type annotation:
---@type integer, string
for s, r in str:gmatch("[,]?%s*()([^,]+)%s*[,]?") do
...
end
Instead I get a Can not infer type. error for r and s is shown as of type string
Reproduction steps
Additional Notes
I think #1367 enabled this, but only for primitive for loops.
Log File
No response
You can use @cast annotation for a workaround, but I think this will be a better alternative to that.
---@param s string
Is that documented somewhere? I feel like it's somewhat unintuitive
Maybe @type could also be supported (or even be used instead), since I feel like it's more in line with a variable assignment than a function definition.