lua-language-server
lua-language-server copied to clipboard
generic in the loop
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
Actual Behaviour
Reproduction steps
---@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
If the type of the table is table<integer>, only the keys will be considered but not the values
---@generic T: table, K, V
---@param t T
---@return fun(table: table<K, V>): {first: K, second: V}
---@return 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 table<integer, integer>
local test_table = {}
for itr in test_function(test_table) do
local test2 = itr.first;
local test3 = itr.second;
end