From 47beee7d7085af35f6869cb349e27dd09b82e7a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 16 Jun 2022 20:57:50 +0800 Subject: infer `nil` as redundant return value --- script/vm/compiler.lua | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'script/vm/compiler.lua') 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) -- cgit v1.2.3