summaryrefslogtreecommitdiff
path: root/script/vm/compiler.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-06-18 01:45:57 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-06-18 01:45:57 +0800
commitbc4e205a4953a7f3a99bafc9fc88295f929beab1 (patch)
treeef92cc3c1438dd292a6df754af53df5d805f1a53 /script/vm/compiler.lua
parent5099d8be7125b948691d099b0e0084a72620293b (diff)
downloadlua-language-server-bc4e205a4953a7f3a99bafc9fc88295f929beab1.zip
update
Diffstat (limited to 'script/vm/compiler.lua')
-rw-r--r--script/vm/compiler.lua44
1 files changed, 35 insertions, 9 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua
index 36b826ae..12ef2a7c 100644
--- a/script/vm/compiler.lua
+++ b/script/vm/compiler.lua
@@ -686,6 +686,7 @@ local function selectNode(source, list, index)
if not exp then
return nil
end
+ ---@type vm.node?
local result
if exp.type == 'call' then
result = getReturn(exp.node, index, exp.args)
@@ -694,30 +695,27 @@ local function selectNode(source, list, index)
return vm.getNode(source)
end
else
+ ---@type vm.node
result = vm.compileNode(exp)
+ if result and exp.type == 'varargs' and result:isEmpty() then
+ result:merge(vm.declareGlobal('type', 'unknown'))
+ end
end
if source.type == 'function.return' then
-- remove any for returns
local rtnNode = vm.createNode()
- local hasKnownType
for n in result:eachObject() do
if guide.isLiteral(n) then
- hasKnownType = true
rtnNode:merge(n)
end
if n.type == 'global' and n.cate == 'type' then
- if n.name ~= 'any'
- and n.name ~= 'unknown' then
- hasKnownType = true
+ if n.name ~= 'any' then
rtnNode:merge(n)
end
else
rtnNode:merge(n)
end
end
- if not hasKnownType then
- rtnNode:merge(vm.declareGlobal('type', 'unknown'))
- end
vm.setNode(source, rtnNode)
return rtnNode
end
@@ -1424,8 +1422,36 @@ local compilerSwitch = util.switch()
end
end
if func.returns and not hasMarkDoc then
+ local hasReturn
for _, rtn in ipairs(func.returns) do
- selectNode(source, rtn, index)
+ if selectNode(source, rtn, index) then
+ hasReturn = true
+ end
+ end
+ if hasReturn then
+ local hasKnownType
+ local hasUnknownType
+ for n in vm.getNode(source):eachObject() do
+ if guide.isLiteral(n) then
+ if n.type ~= 'nil' then
+ hasKnownType = true
+ break
+ end
+ goto CONTINUE
+ end
+ if n.type == 'global' and n.cate == 'type' then
+ if n.name ~= 'nil' then
+ hasKnownType = true
+ break
+ end
+ goto CONTINUE
+ end
+ hasUnknownType = true
+ ::CONTINUE::
+ end
+ if not hasKnownType and hasUnknownType then
+ vm.setNode(source, vm.getGlobal('type', 'unknown'))
+ end
end
end
if vm.getNode(source):isEmpty() then