From dd1c80a8ef2c05aebe1c3650513fa7f6a360810e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 14 Dec 2018 19:14:34 +0800 Subject: =?UTF-8?q?=E6=9A=82=E4=B8=94=E5=85=88=E8=BF=99=E6=A0=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/matcher/vm.lua | 16 ++++++++++++++-- server/test/hover/init.lua | 2 +- server/test/type_inference/init.lua | 4 ++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua index b1d303a9..2d1f025a 100644 --- a/server/src/matcher/vm.lua +++ b/server/src/matcher/vm.lua @@ -414,12 +414,12 @@ function mt:call(func, values) if lib then if lib.args then for i, arg in ipairs(lib.args) do - self:inference(self:getFunctionArg(func, i), arg.type) + self:inference(self:getFunctionArg(func, i), arg.type or 'any') end end if lib.returns then for i, rtn in ipairs(lib.returns) do - self:inference(self:getFunctionReturns(func, i), rtn.type) + self:inference(self:getFunctionReturns(func, i), rtn.type or 'any') end end if lib.special then @@ -461,6 +461,9 @@ function mt:setFunctionReturn(func, index, value) end function mt:getFunctionReturns(func, i) + if func.maxReturns and i and func.maxReturns < i then + return self:createValue('nil') + end if not func.returns then func.returns = { type = 'list', @@ -532,9 +535,18 @@ function mt:getLibValue(lib, parentType, v) elseif tp == 'function' then value = self:createValue('function') if lib.returns then + local dots for i, rtn in ipairs(lib.returns) do self:setFunctionReturn(value, i, self:getLibValue(rtn, parentType)) + if rtn.type == '...' then + dots = true + end end + if not dots then + value.maxReturns = #lib.returns + end + else + value.maxReturns = 0 end if lib.args then local values = {} diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua index 8bbde91f..31e604f3 100644 --- a/server/test/hover/init.lua +++ b/server/test/hover/init.lua @@ -152,7 +152,7 @@ TEST[[ TEST [[ local = collectgarbage() ]] -"nil v" +"any v" TEST [[ local type diff --git a/server/test/type_inference/init.lua b/server/test/type_inference/init.lua index 820d00c9..9f5887f1 100644 --- a/server/test/type_inference/init.lua +++ b/server/test/type_inference/init.lua @@ -177,3 +177,7 @@ TEST 'integer' [[ for in ipairs(t) do end ]] + +TEST 'any' [[ +local = next() +]] -- cgit v1.2.3