diff options
-rw-r--r-- | script/parser/luadoc.lua | 1 | ||||
-rw-r--r-- | script/vm/compiler.lua | 19 |
2 files changed, 16 insertions, 4 deletions
diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 4d9de5be..6adbfa68 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -6,6 +6,7 @@ local parser = require 'parser.newparser' local TokenTypes, TokenStarts, TokenFinishs, TokenContents, TokenMarks local Ci, Offset, pushWarning, NextComment, Lines local parseType +---@type any local Parser = re.compile([[ Main <- (Token / Sp)* Sp <- %s+ diff --git a/script/vm/compiler.lua b/script/vm/compiler.lua index 76e5c8d4..dad7d8f6 100644 --- a/script/vm/compiler.lua +++ b/script/vm/compiler.lua @@ -484,17 +484,28 @@ local function selectNode(source, list, index) result = m.compileNode(exp) end if source.type == 'function.return' then + -- remove any for returns + local rtnNode = union() local hasKnownType for n in nodeMgr.eachNode(result) do - if guide.isLiteral(n) - or (n.type == 'global' and n.cate == 'type') then + if guide.isLiteral(n) then hasKnownType = true - break + rtnNode:merge(n) + end + if n.type == 'global' and n.cate == 'type' then + if n.name ~= 'any' + and n.name ~= 'unknown' then + hasKnownType = true + rtnNode:merge(n) + end + else + rtnNode:merge(n) end end if not hasKnownType then - result = nodeMgr.mergeNode(result, globalMgr.getGlobal('type', 'unknown')) + rtnNode:merge(globalMgr.getGlobal('type', 'unknown')) end + return nodeMgr.setNode(source, rtnNode) end return nodeMgr.setNode(source, result) end |