summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/src/matcher/vm.lua21
-rw-r--r--server/test/hover/init.lua13
2 files changed, 32 insertions, 2 deletions
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index f054f800..dfa0d0d9 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -664,12 +664,20 @@ function mt:call(func, values)
if lib then
if lib.args then
for i, arg in ipairs(lib.args) do
- self:inference(self:getFunctionArg(func, i), arg.type or 'any')
+ if arg.type == '...' then
+ self:inference(self:getFunctionArg(func, i), 'any')
+ else
+ self:inference(self:getFunctionArg(func, i), arg.type or 'any')
+ end
end
end
if lib.returns then
for i, rtn in ipairs(lib.returns) do
- self:inference(self:getFunctionReturns(func, i), rtn.type or 'any')
+ if rtn.type == '...' then
+ self:inference(self:getFunctionReturns(func, i), 'any')
+ else
+ self:inference(self:getFunctionReturns(func, i), rtn.type or 'any')
+ end
end
end
if lib.special then
@@ -750,12 +758,19 @@ function mt:getFunctionReturns(func, i)
end
function mt:inference(value, type)
+ if type == '...' then
+ error('Value type cant be ...')
+ end
if value.type == 'any' and type ~= 'nil' then
value.type = type
end
end
function mt:createValue(tp, source, v)
+ if tp == '...' then
+ error('Value type cant be ...')
+ end
+ -- TODO lib里的多类型
if type(tp) == 'table' then
tp = tp[1]
end
@@ -834,6 +849,8 @@ function mt:getLibValue(lib, parentType, v)
value = self:createValue('integer', nil, v or lib.value)
elseif tp == 'nil' then
value = self:createValue('nil')
+ elseif tp == '...' then
+ value = self:createValue('any')
else
value = self:createValue(tp or 'any')
end
diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua
index 6e7c8b01..9b22e3dd 100644
--- a/server/test/hover/init.lua
+++ b/server/test/hover/init.lua
@@ -235,3 +235,16 @@ end
local <?n?> = f()
]]
[[any n]]
+
+TEST [[
+local <?n?> = table.unpack(t)
+]]
+[[any n]]
+
+TEST [[
+local <?n?>
+table.pack(n)
+]]
+[[
+any n
+]]