LuaLS / LuaLS/lua-language-server

Cannot type for-loop variable

Open
#2,487 3 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Lua
Stars
4.4k
Forks
442
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start with the Lua snippet and inspect how @type annotations are applied to generic for-loop variables, comparing that path with the primitive for-loop support referenced in #1367. Done means s is inferred as integer, r as string, and the diagnostic is cleared.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
devtools, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.