LuaLS / LuaLS/lua-language-server

generic in the loop

Open
#2,580 1 comment 0 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?

Visual Studio Code Extension (sumneko.lua)

### Which OS are you using?

Windows

### What is the issue affecting?

Annotations, Type Checking

### Expected Behaviour

![Снимок экрана 2024-03-24 160655](https://github.com/LuaLS/lua-language-server/assets/57856647/38560c75-7854-4b52-87d6-0a74fbc395e3)

### Actual Behaviour

![Снимок экрана 2024-03-24 162116](https://github.com/LuaLS/lua-language-server/assets/57856647/328b20ed-2211-40e8-b67e-132399705813)

### Reproduction steps

```lua
---@generic T
---@param t T[]
---@return fun(): { first: integer, second: T }
local function test_function(t)
local ending = #t
local begining = 1

local j = begining

return function()
if ending < j then
return nil
end

local i = t[j]

j = j + 1

if i then return { first = j - 1, second = i } end
end
end

---@type integer[]
local test_table = {}

local test_result = test_function(test_table)()

local test1 = test_result.second

for itr in test_function(test_table) do
local test2 = itr.first;
local test3 = itr.second;
end

```

### Additional Notes

_No response_

### 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

Start by running the Lua reproduction in the issue and compare the inferred types with the Expected Behaviour and Actual Behaviour screenshots. Trace the language server's annotation and type-checking entry points for generic functions and iterator returns, then verify that the reported types match the expected result.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua, vscode
Domain
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.