summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/parser/guide.lua8
-rw-r--r--test/type_inference/init.lua30
3 files changed, 39 insertions, 0 deletions
diff --git a/changelog.md b/changelog.md
index a2363305..d6c9d1fb 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,6 +1,7 @@
# changelog
## 1.17.3
+* `CHG` intelli-scense: treat `V[]` as `table<integer, V>` in `pairs`
* `FIX` [#435](https://github.com/sumneko/lua-language-server/issues/435)
## 1.17.2
diff --git a/script/parser/guide.lua b/script/parser/guide.lua
index 85356e90..ae7fec25 100644
--- a/script/parser/guide.lua
+++ b/script/parser/guide.lua
@@ -1665,6 +1665,14 @@ local function stepRefOfGenericCrossTable(status, doc, typeName)
if res.type == 'doc.type.table' then
return res[where]
end
+ if res.type == 'doc.type.array' then
+ if where == 'key' then
+ return status.interface and status.interface.docType('integer')[1]
+ end
+ if where == 'value' then
+ return res.node
+ end
+ end
end
end
end
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 0dab932e..6ab57a06 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -563,6 +563,36 @@ for _, <?v?> in ipairs(t) do
end
]]
+TEST 'boolean' [[
+---@generic T: table, K, V
+---@param t T
+---@return fun(table: table<K, V>, index: K):K, V
+---@return T
+---@return nil
+local function pairs(t) end
+
+---@type boolean[]
+local t
+
+for k, <?v?> in pairs(t) do
+end
+]]
+
+TEST 'integer' [[
+---@generic T: table, K, V
+---@param t T
+---@return fun(table: table<K, V>, index: K):K, V
+---@return T
+---@return nil
+local function pairs(t) end
+
+---@type boolean[]
+local t
+
+for <?k?>, v in pairs(t) do
+end
+]]
+
TEST 'E' [[
---@class A
---@class B: A