Skip to content

Commit b9e9b9e

Browse files
committed
#435 treat V[] as table<integer, V> in pairs
1 parent 2e4d093 commit b9e9b9e

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

Diff for: changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# changelog
22

33
## 1.17.3
4+
* `CHG` intelli-scense: treat `V[]` as `table<integer, V>` in `pairs`
45
* `FIX` [#435](https://github.com/sumneko/lua-language-server/issues/435)
56

67
## 1.17.2

Diff for: script/parser/guide.lua

+8
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,14 @@ local function stepRefOfGenericCrossTable(status, doc, typeName)
16651665
if res.type == 'doc.type.table' then
16661666
return res[where]
16671667
end
1668+
if res.type == 'doc.type.array' then
1669+
if where == 'key' then
1670+
return status.interface and status.interface.docType('integer')[1]
1671+
end
1672+
if where == 'value' then
1673+
return res.node
1674+
end
1675+
end
16681676
end
16691677
end
16701678
end

Diff for: test/type_inference/init.lua

+30
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,36 @@ for _, <?v?> in ipairs(t) do
563563
end
564564
]]
565565

566+
TEST 'boolean' [[
567+
---@generic T: table, K, V
568+
---@param t T
569+
---@return fun(table: table<K, V>, index: K):K, V
570+
---@return T
571+
---@return nil
572+
local function pairs(t) end
573+
574+
---@type boolean[]
575+
local t
576+
577+
for k, <?v?> in pairs(t) do
578+
end
579+
]]
580+
581+
TEST 'integer' [[
582+
---@generic T: table, K, V
583+
---@param t T
584+
---@return fun(table: table<K, V>, index: K):K, V
585+
---@return T
586+
---@return nil
587+
local function pairs(t) end
588+
589+
---@type boolean[]
590+
local t
591+
592+
for <?k?>, v in pairs(t) do
593+
end
594+
]]
595+
566596
TEST 'E' [[
567597
---@class A
568598
---@class B: A

0 commit comments

Comments
 (0)