summaryrefslogtreecommitdiff
path: root/test/type_inference
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-02-26 17:04:38 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-02-26 17:04:38 +0800
commit0ded390ce1b477e62963e8e67488b00ba8427a35 (patch)
treea11b5fe47930c668c6640eec3391e25ca04a27bf /test/type_inference
parent2c688721092f1fe102514eed6a836ccfeb12a789 (diff)
downloadlua-language-server-0ded390ce1b477e62963e8e67488b00ba8427a35.zip
improve infer cross `pairs`
Diffstat (limited to 'test/type_inference')
-rw-r--r--test/type_inference/init.lua53
1 files changed, 51 insertions, 2 deletions
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 28bdd0e9..725b19fe 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -472,15 +472,63 @@ local <?r?> = f()
]]
TEST 'string' [[
+---@generic K, V
+---@return fun(arg: table<K, V>):K, V
+local function f() end
+
+local f2 = f()
+
+---@type table<string, boolean>
+local t
+
+local <?k?>, v = f2(t)
+]]
+
+TEST 'string' [[
+---@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
+
+local f = pairs(t)
+
+---@type table<string, boolean>
+local t
+
+for <?k?>, v in f, 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
+
+local f = pairs(t)
+
+---@type table<string, boolean>
+local t
+
+for k, <?v?> in f, t do
+end
+]]
+
+TEST 'string' [[
---@generic T: table, K, V
---@param t T
---@return fun(table: table<K, V>, index: K):K, V
---@return T
---@return nil
-function pairs(t) end
+local function pairs(t) end
---@type table<string, boolean>
local t
+
for <?k?>, v in pairs(t) do
end
]]
@@ -491,10 +539,11 @@ TEST 'boolean' [[
---@return fun(table: table<K, V>, index: K):K, V
---@return T
---@return nil
-function pairs(t) end
+local function pairs(t) end
---@type table<string, boolean>
local t
+
for k, <?v?> in pairs(t) do
end
]]