lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

Cannot type for-loop variable

Open saecki opened this issue 1 year ago • 3 comments

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

saecki avatar Jan 17 '24 17:01 saecki

You can use @cast annotation for a workaround, but I think this will be a better alternative to that.

0komo avatar Jan 19 '24 10:01 0komo

---@param s string

CppCXY avatar Jan 19 '24 11:01 CppCXY

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.

saecki avatar Jan 19 '24 14:01 saecki