From d796bb67d5135d152b9f627b69e57377c83d1a66 Mon Sep 17 00:00:00 2001 From: Benjamin Dobell Date: Mon, 13 Nov 2023 16:52:58 +1100 Subject: [PATCH] Fixed mishandling of variadic params in the presence expressions with multiple return values --- src/main/java/com/tang/intellij/lua/ty/Ty.kt | 4 ++-- src/test/resources/inspections/varargs.lua | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/tang/intellij/lua/ty/Ty.kt b/src/main/java/com/tang/intellij/lua/ty/Ty.kt index 6a10ff42..43f5347b 100644 --- a/src/main/java/com/tang/intellij/lua/ty/Ty.kt +++ b/src/main/java/com/tang/intellij/lua/ty/Ty.kt @@ -418,11 +418,11 @@ fun ITy.matchSignature(context: SearchContext, call: LuaCallExpr, processProblem if (parameterCount < concreteArgTypes.size) { if (varargParamTy != null) { - for (i in parameterCount until args.size) { + for (i in parameterCount until concreteArgTypes.size) { val argType = concreteArgTypes.getOrNull(i)?.ty?.let { if (it is TyMultipleResults) it.list.first() else it } ?: variadicArg!!.ty - val argExpr = args.get(i) + val argExpr = args.getOrNull(i) ?: args.last() val varianceFlags = if (argExpr is LuaTableExpr) TyVarianceFlags.WIDEN_TABLES else 0 if (processProblem != null) { diff --git a/src/test/resources/inspections/varargs.lua b/src/test/resources/inspections/varargs.lua index ab09f09a..bbd58f59 100644 --- a/src/test/resources/inspections/varargs.lua +++ b/src/test/resources/inspections/varargs.lua @@ -239,3 +239,18 @@ local function acceptsFun(...) a[1]("a string", 1) a[1]("a string", "a string") end + +---@vararg string[] +---@return string[] +local function acceptStringArrays(...) + return {} +end + +---@return string[], number +local function returnsStringArrayAndNumber() + return { "a string" }, 1 +end + +---@type string[] +local strArr = acceptStringArrays(returnsStringArrayAndNumber()) +strArr = acceptStringArrays((returnsStringArrayAndNumber()))