From e665f6f914eec9e3beca165f1ad7ff432573c740 Mon Sep 17 00:00:00 2001 From: sumneko Date: Fri, 11 Mar 2022 18:05:49 +0800 Subject: update --- script/vm/compiler.lua | 10 ++++++++-- test/type_inference/init.lua | 8 ++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index c70f5d84..af810e19 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -261,11 +261,12 @@ local function getReturn(func, index, args) end local node = m.compileNode(func) ---@type vm.node.union - local result + local result, hasCalled if node then for cnode in nodeMgr.eachNode(node) do if cnode.type == 'function' or cnode.type == 'doc.type.function' then + hasCalled = true local returnNode = getReturnOfFunction(cnode, index) if returnNode and returnNode.type == 'generic' then returnNode = returnNode:resolve(args) @@ -277,6 +278,9 @@ local function getReturn(func, index, args) end end end + if not hasCalled then + result = globalMgr.getGlobal('type', 'unknown') + end return result end @@ -374,7 +378,9 @@ local function selectNode(source, list, index) end result = result or m.compileNode(exp) - or union() + if not result then + return nodeMgr.setNode(source, result) + end local hasKnownType for n in nodeMgr.eachNode(result) do if guide.isLiteral(n) diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 9edc49c3..f62ca013 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -289,6 +289,14 @@ end = x() ]] +TEST 'unknown' [[ +local function x() + return nil + return f() +end +_, = x() +]] + TEST 'integer' [[ local function x() return 1 -- cgit v1.2.3