diff options
author | sumneko <sumneko@hotmail.com> | 2019-05-27 11:32:49 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-05-27 11:32:49 +0800 |
commit | 23c895e096b8bf9c0873ce3efaca862db246e236 (patch) | |
tree | f8d38b8228aa475e6d1bf9d428a37c9ef478dc4d | |
parent | c72ec4e93a463fea2d826f0fbac7aede460a045f (diff) | |
download | lua-language-server-23c895e096b8bf9c0873ce3efaca862db246e236.zip |
fixed #40 强制使用 @return
-rw-r--r-- | server/src/vm/function.lua | 14 | ||||
-rw-r--r-- | server/test/hover/init.lua | 27 |
2 files changed, 39 insertions, 2 deletions
diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua index 1106a0c9..a6f2b0cf 100644 --- a/server/src/vm/function.lua +++ b/server/src/vm/function.lua @@ -145,7 +145,7 @@ function mt:loadLabel(name) return nil end -function mt:setReturn(index, value) +function mt:rawSetReturn(index, value) if self._removed then return end @@ -161,10 +161,20 @@ function mt:setReturn(index, value) end end +function mt:setReturn(index, value) + if self._emmyReturns then + return + end + return self:rawSetReturn(index, value) +end + function mt:mergeReturn(index, value) if self._removed then return end + if self._emmyReturns then + return + end self:set('hasReturn', true) if not self.returns then self.returns = createMulti() @@ -324,7 +334,7 @@ function mt:run(vm) value:mergeType(destValue) end end - self:setReturn(i, value) + self:rawSetReturn(i, value) end end end diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua index e568335d..cff6af65 100644 --- a/server/test/hover/init.lua +++ b/server/test/hover/init.lua @@ -769,3 +769,30 @@ local names: { [*integer]: string, } ]] + +TEST [[ +---@return any +function <?f?>() + ---@type integer + local a + return a +end +]] +[[ +function f() + -> any +]] + +TEST [[ +---@return any +function f() + ---@type integer + local a + return a +end + +local <?x?> = f() +]] +[[ +local x: any +]] |