diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-16 20:57:50 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-16 20:57:50 +0800 |
commit | 47beee7d7085af35f6869cb349e27dd09b82e7a4 (patch) | |
tree | 8b339629804656edc55c375d36c8769a0b5ff986 /script | |
parent | 8a9e8d9cfd12d43496c2bf16f70874af550d4e7e (diff) | |
download | lua-language-server-47beee7d7085af35f6869cb349e27dd09b82e7a4.zip |
infer `nil` as redundant return value
Diffstat (limited to 'script')
-rw-r--r-- | script/vm/compiler.lua | 10 | ||||
-rw-r--r-- | script/vm/type.lua | 3 |
2 files changed, 11 insertions, 2 deletions
diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 29de39ae..65df3a1d 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -667,7 +667,7 @@ local function selectNode(source, list, index) if list[i] then local last = list[i] if last.type == 'call' - or last.type == '...' then + or last.type == 'varargs' then index = index - i + 1 exp = last end @@ -1376,9 +1376,11 @@ local compilerSwitch = util.switch() local hasMarkDoc if func.bindDocs then local sign = getObjectSign(func) + local lastReturn for _, doc in ipairs(func.bindDocs) do if doc.type == 'doc.return' then for _, rtn in ipairs(doc.returns) do + lastReturn = rtn if rtn.returnIndex == index then hasMarkDoc = true local hasGeneric @@ -1396,12 +1398,18 @@ local compilerSwitch = util.switch() end end end + if lastReturn and not hasMarkDoc and lastReturn.types[1][1] == '...' then + vm.setNode(source, vm.getGlobal('type', 'unknown')) + end end if func.returns and not hasMarkDoc then for _, rtn in ipairs(func.returns) do selectNode(source, rtn, index) end end + if vm.getNode(source):isEmpty() then + vm.setNode(source, vm.getGlobal('type', 'nil')) + end end) : case 'main' : call(function (source) diff --git a/script/vm/type.lua b/script/vm/type.lua index 8027e933..3eb42e51 100644 --- a/script/vm/type.lua +++ b/script/vm/type.lua @@ -39,7 +39,8 @@ function vm.isSubNode(child, parent, mark) mark = mark or {} local childName = getNodeName(child) local parentName = getNodeName(parent) - if childName == 'any' or parentName == 'any' then + if childName == 'any' + or parentName == 'any' then return true end |