diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-04-08 20:11:14 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-04-08 20:11:14 +0800 |
commit | 097a36edf4cece5ce1b590adffc6de0d2929e995 (patch) | |
tree | 45a73f85fcc0c9c2cc393d1617eb95ed686cdd93 | |
parent | 1e6b168fa6d7a4922205cd19519e01f25898017e (diff) | |
download | lua-language-server-097a36edf4cece5ce1b590adffc6de0d2929e995.zip |
fix
-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 |