summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2022-03-11 04:04:08 +0800
committersumneko <sumneko@hotmail.com>2022-03-11 04:04:08 +0800
commit36976b3df2d19d6b2593a25527516218049d630a (patch)
tree154152c906b96eecbe9237bc0504115d96264693 /test
parentbb02090e9f63355cda301a66571da9d2cd141334 (diff)
downloadlua-language-server-36976b3df2d19d6b2593a25527516218049d630a.zip
update
Diffstat (limited to 'test')
-rw-r--r--test/type_inference/init.lua93
1 files changed, 89 insertions, 4 deletions
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 7721e776..46fd2cad 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -540,6 +540,22 @@ print(t.<?a?>)
]]
TEST 'integer' [[
+---@generic K
+---@type fun(a?: K):K
+local f
+
+local <?n?> = f(1)
+]]
+
+TEST 'unknown' [[
+---@generic K
+---@type fun(a?: K):K
+local f
+
+local <?n?> = f(nil)
+]]
+
+TEST 'integer' [[
---@class integer
---@generic T: table, V
@@ -685,22 +701,91 @@ local f2 = f(1)
local i, <?v?> = f2(true)
]]
+TEST 'fun(table: table<<K>, <V>>, index?: <K>):<K>, <V>' [[
+---@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 <?next?> = pairs(dummy)
+]]
+
TEST 'string' [[
----@class 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 next = pairs(dummy)
+
+---@type table<string, boolean>
+local t
+local <?k?>, v = next(t)
+]]
+
+TEST 'boolean' [[
---@generic T: table, K, V
---@param t T
----@return fun(table: table<K, V>, index: K):K, V
+---@return fun(table: table<K, V>, index?: K):K, V
---@return T
---@return nil
local function pairs(t) end
-local f = pairs(t)
+local next = pairs(dummy)
+
+---@type table<string, boolean>
+local t
+local k, <?v?> = next(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 next = pairs(dummy)
+
+---@type table<string, boolean>
+local t
+local <?k?>, v = next(t, nil)
+]]
+
+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 next = pairs(dummy)
+
+---@type table<string, boolean>
+local t
+local k, <?v?> = next(t, nil)
+]]
+
+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 next = pairs(dummy)
---@type table<string, boolean>
local t
-for <?k?>, v in f, t do
+for <?k?>, v in next, t do
end
]]