summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2022-03-11 16:52:51 +0800
committersumneko <sumneko@hotmail.com>2022-03-11 16:52:51 +0800
commit341949e632439b76485f4707155df93f9dd4b258 (patch)
tree179b653d4a7b157a6576cb9424fdb0b85e260ed3
parent36976b3df2d19d6b2593a25527516218049d630a (diff)
downloadlua-language-server-341949e632439b76485f4707155df93f9dd4b258.zip
update
-rw-r--r--script/vm/compiler.lua10
-rw-r--r--script/vm/node.lua11
-rw-r--r--script/vm/sign.lua8
-rw-r--r--test/type_inference/init.lua10
4 files changed, 21 insertions, 18 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 6b73b197..c70f5d84 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -353,10 +353,11 @@ local function selectNode(source, list, index)
else
for i = index, 1, -1 do
if list[i] then
- exp = list[i]
- if exp.type == 'call'
- or exp.type == '...' then
+ local last = list[i]
+ if last.type == 'call'
+ or last.type == '...' then
index = index - i + 1
+ exp = last
end
break
end
@@ -377,6 +378,9 @@ local function selectNode(source, list, index)
local hasKnownType
for n in nodeMgr.eachNode(result) do
if guide.isLiteral(n)
+ or n.type == 'doc.type.function'
+ or n.type == 'doc.type.table'
+ or n.type == 'doc.type.integer'
or (n.type == 'global' and n.cate == 'type') then
hasKnownType = true
break
diff --git a/script/vm/node.lua b/script/vm/node.lua
index 3368ab05..082a5e87 100644
--- a/script/vm/node.lua
+++ b/script/vm/node.lua
@@ -38,10 +38,14 @@ function m.setNode(source, node)
m.nodeCache[source] = m.mergeNode(me, node)
end
+function m.getNode(source)
+ return m.nodeCache[source]
+end
+
---@param node vm.node
---@return vm.node.union
function m.addOptional(node)
- if node.type ~= 'union' then
+ if not node or node.type ~= 'union' then
node = union(node)
end
node = node:addOptional()
@@ -49,8 +53,11 @@ function m.addOptional(node)
end
---@param node vm.node
----@return vm.node.union
+---@return vm.node.union?
function m.removeOptional(node)
+ if not node then
+ return node
+ end
if node.type ~= 'union' then
node = union(node)
end
diff --git a/script/vm/sign.lua b/script/vm/sign.lua
index 059d82bb..2c440902 100644
--- a/script/vm/sign.lua
+++ b/script/vm/sign.lua
@@ -82,10 +82,12 @@ function mt:resolve(argNodes)
end
for n in nodeMgr.eachNode(sign) do
node = compiler.compileNode(node)
- if sign.optional then
- node = nodeMgr.removeOptional(node)
+ if node then
+ if sign.optional then
+ node = nodeMgr.removeOptional(node)
+ end
+ resolve(n, node)
end
- resolve(n, node)
end
end
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 46fd2cad..9edc49c3 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -808,8 +808,6 @@ end
]]
TEST 'string' [[
----@class string
-
---@generic T: table, K, V
---@param t T
---@return fun(table: table<K, V>, index?: K):K, V
@@ -824,8 +822,6 @@ end
]]
TEST 'boolean' [[
----@class boolean
-
---@generic T: table, K, V
---@param t T
---@return fun(table: table<K, V>, index: K):K, V
@@ -841,8 +837,6 @@ end
]]
TEST 'boolean' [[
----@class boolean
-
---@generic T: table, V
---@param t T
---@return fun(table: V[], i?: integer):integer, V
@@ -858,8 +852,6 @@ end
]]
TEST 'boolean' [[
----@class boolean
-
---@generic T: table, K, V
---@param t T
---@return fun(table: table<K, V>, index: K):K, V
@@ -875,8 +867,6 @@ end
]]
TEST 'integer' [[
----@class integer
-
---@generic T: table, K, V
---@param t T
---@return fun(table: table<K, V>, index?: K):K, V