summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-17 14:49:58 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-17 14:49:58 +0800
commit5aee9577f505ba4cb92e74d49476f7b3e01b5be1 (patch)
treed024aba8ccad0f5786ffa2f9ba3a106abf6ef0c0 /server
parent5c6166c11a8ac9533aefb78890f359c1abf3ccbf (diff)
downloadlua-language-server-5aee9577f505ba4cb92e74d49476f7b3e01b5be1.zip
函数返回值不参考nil
Diffstat (limited to 'server')
-rw-r--r--server/src/matcher/vm.lua22
1 files changed, 18 insertions, 4 deletions
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index 2d1f025a..48e63670 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -440,6 +440,20 @@ function mt:getCurrentFunction()
return self.chunk.func
end
+function mt:mergeFunctionReturn(func, index, value)
+ if not func.returns[index] then
+ func.returns[index] = value
+ return
+ end
+ if value.type == 'nil' then
+ return
+ end
+ if value == 'any' and func.returns[index] ~= 'nil' then
+ return
+ end
+ func.returns[index] = value
+end
+
function mt:setFunctionReturn(func, index, value)
func.hasReturn = true
if not func.returns then
@@ -450,13 +464,13 @@ function mt:setFunctionReturn(func, index, value)
if value then
if value.type == 'list' then
for i, v in ipairs(value) do
- func.returns[index+i-1] = v
+ self:mergeFunctionReturn(func, index+i-1, v)
end
else
- func.returns[index] = value
+ self:mergeFunctionReturn(func, index, value)
end
else
- func.returns[index] = self:createValue('any')
+ self:mergeFunctionReturn(func, index, self:createValue('any'))
end
end
@@ -482,7 +496,7 @@ function mt:getFunctionReturns(func, i)
end
function mt:inference(value, type)
- if value.type == 'any' then
+ if value.type == 'any' and type ~= 'nil' then
value.type = type
end
end