From 34d32a478bcd066baf49ccf36f5f26a132cbfab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Mon, 7 Nov 2022 21:00:59 +0800 Subject: fix warning --- script/vm/function.lua | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'script/vm/function.lua') diff --git a/script/vm/function.lua b/script/vm/function.lua index b4466668..bdd7e229 100644 --- a/script/vm/function.lua +++ b/script/vm/function.lua @@ -297,22 +297,36 @@ function vm.countList(list, mark) if not lastArg then return 0, 0, 0 end + ---@type integer, number, integer + local min, max, def = #list, #list, #list if lastArg.type == '...' - or lastArg.type == 'varargs' then - return #list - 1, math.huge, #list - end - if lastArg.type == 'call' then + or lastArg.type == 'varargs' + or (lastArg.type == 'doc.type' and lastArg.name and lastArg.name[1] == '...') then + max = math.huge + elseif lastArg.type == 'call' then if not mark then mark = {} end if mark[lastArg] then - return #list - 1, math.huge, #list + min = min - 1 + max = math.huge + else + mark[lastArg] = true + local rmin, rmax, rdef = vm.countReturnsOfCall(lastArg.node, lastArg.args, mark) + return min - 1 + rmin, max - 1 + rmax, def - 1 + rdef + end + end + for i = min, 1, -1 do + local arg = list[i] + if arg.type == 'doc.type' + and ((arg.name and arg.name[1] == '...') + or vm.compileNode(arg):isNullable()) then + min = i - 1 + else + break end - mark[lastArg] = true - local rmin, rmax, rdef = vm.countReturnsOfCall(lastArg.node, lastArg.args, mark) - return #list - 1 + rmin, #list - 1 + rmax, #list - 1 + rdef end - return #list, #list, #list + return min, max, def end ---@param func parser.object -- cgit v1.2.3