From 5093bca814e5f3471b1be28f1c9d71d6be388e60 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, 13 May 2024 10:47:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/vm/function.lua | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/script/vm/function.lua b/script/vm/function.lua index 1a916a1c3..1e3083172 100644 --- a/script/vm/function.lua +++ b/script/vm/function.lua @@ -1,6 +1,7 @@ ---@class vm local vm = require 'vm.vm' local guide = require 'parser.guide' +local util = require 'utility' ---@param arg parser.object ---@return parser.object? @@ -360,18 +361,28 @@ function vm.getExactMatchedFunctions(func, args) if not args or not funcs then return funcs end + if #funcs == 1 then + return funcs + end local uri = guide.getUri(func) - local result = {} - for _, n in ipairs(funcs) do - if not vm.isVarargFunctionWithOverloads(n) - and isAllParamMatched(uri, args, n.args) then - result[#result+1] = n + local needRemove + for i, n in ipairs(funcs) do + if vm.isVarargFunctionWithOverloads(n) + or not isAllParamMatched(uri, args, n.args) then + if not needRemove then + needRemove = {} + end + needRemove[#needRemove+1] = i end end - if #result == 0 then + if not needRemove then + return funcs + end + if #needRemove == #funcs then return nil end - return result + util.tableMultiRemove(funcs, needRemove) + return funcs end ---@param func parser.object @@ -414,23 +425,31 @@ function vm.isVarargFunctionWithOverloads(func) if not func.args then return false end + if func._varargFunction ~= nil then + return func._varargFunction + end if func.args[1] and func.args[1].type == 'self' then if not func.args[2] or func.args[2].type ~= '...' then + func._varargFunction = false return false end else if not func.args[1] or func.args[1].type ~= '...' then + func._varargFunction = false return false end end if not func.bindDocs then + func._varargFunction = false return false end for _, doc in ipairs(func.bindDocs) do if doc.type == 'doc.overload' then + func._varargFunction = true return true end end + func._varargFunction = false return false end