Skip to content

Commit

Permalink
Fixed mishandling of variadic params in the presence expressions with…
Browse files Browse the repository at this point in the history
… multiple return values
  • Loading branch information
Benjamin-Dobell committed Nov 13, 2023
1 parent 20e97a0 commit d796bb6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/main/java/com/tang/intellij/lua/ty/Ty.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
15 changes: 15 additions & 0 deletions src/test/resources/inspections/varargs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,18 @@ local function acceptsFun(...)
a[1]("a string", 1)
a[1]("a string", <error descr="Type mismatch. Required: 'number' Found: '\"a string\"'">"a string"</error>)
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(<error descr="Type mismatch. Required: 'string[]' Found: 'number'">returnsStringArrayAndNumber()</error>)
strArr = acceptStringArrays((returnsStringArrayAndNumber()))

0 comments on commit d796bb6

Please sign in to comment.