summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script/core/diagnostics/redundant-parameter.lua6
-rw-r--r--test/diagnostics/common.lua24
2 files changed, 30 insertions, 0 deletions
diff --git a/script/core/diagnostics/redundant-parameter.lua b/script/core/diagnostics/redundant-parameter.lua
index 2b7f1230..deda918a 100644
--- a/script/core/diagnostics/redundant-parameter.lua
+++ b/script/core/diagnostics/redundant-parameter.lua
@@ -26,6 +26,12 @@ return function (uri, callback)
end
if funcArgs + 1 > #source.args then
local lastArg = source.args[#source.args]
+ if lastArg.type == 'call' and funcArgs > 0 then
+ -- 如果函数接收至少一个参数,那么调用方最后一个参数是函数调用
+ -- 导致的参数数量太多可以忽略。
+ -- 如果函数不接收任何参数,那么任何参数都是错误的。
+ return
+ end
callback {
start = lastArg.start,
finish = lastArg.finish,
diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua
index d640e45a..7d745039 100644
--- a/test/diagnostics/common.lua
+++ b/test/diagnostics/common.lua
@@ -1631,3 +1631,27 @@ function F(x) end
F(k())
]]
+
+TEST [[
+local function f()
+ return 1, 2, 3
+end
+
+local function k()
+end
+
+k(<!f()!>)
+]]
+
+TEST [[
+---@diagnostic disable: unused-local
+local function f()
+ return 1, 2, 3
+end
+
+---@param x integer
+local function k(x)
+end
+
+k(f())
+]]