diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-11-07 21:00:59 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-11-07 21:00:59 +0800 |
commit | 34d32a478bcd066baf49ccf36f5f26a132cbfab8 (patch) | |
tree | b0efdb7103dde9cf5b7f16f3a24886bf555708a7 /script/vm | |
parent | 0618f3793e2687e5e15e9d5a51838d61b306dec5 (diff) | |
download | lua-language-server-34d32a478bcd066baf49ccf36f5f26a132cbfab8.zip |
fix warning
Diffstat (limited to 'script/vm')
-rw-r--r-- | script/vm/function.lua | 32 | ||||
-rw-r--r-- | script/vm/sign.lua | 2 |
2 files changed, 24 insertions, 10 deletions
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 diff --git a/script/vm/sign.lua b/script/vm/sign.lua index 3fc9f981..b70aaec5 100644 --- a/script/vm/sign.lua +++ b/script/vm/sign.lua @@ -312,7 +312,7 @@ function vm.getSign(source) or source.type == 'doc.type.table' or source.type == 'doc.type.array' then local hasGeneric - guide.eachSourceType(source, 'doc.generic.name', function () + guide.eachSourceType(source, 'doc.generic.name', function (_) hasGeneric = true end) if not hasGeneric then |