Skip to content

Commit

Permalink
Corrected resolution of chained function calls returning multiple res…
Browse files Browse the repository at this point in the history
…ults
  • Loading branch information
Benjamin-Dobell committed Mar 28, 2023
1 parent 4135ae2 commit 54ace36
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/main/java/com/tang/intellij/lua/ty/Expressions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,9 @@ private fun LuaIndexExpr.infer(context: SearchContext): ITy? {

//from value
var result: ITy? = null
val prefixType = indexExpr.guessParentType(context)
val prefixType = context.withIndex(0) {
indexExpr.guessParentType(context)
}

Ty.eachResolved(context, prefixType) { ty ->
result = TyUnion.union(context, result, guessFieldType(context, indexExpr, ty))
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/inspections/function_multiple_returns.lua
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,7 @@ end
local function returnBooleanOperationOnMultipleResults(val)
return val > 0 and returnsNumberNumber() or returnsStringString()
end

-- Correctly handle chainged function calls through methods returning multiple results
aString, aNumber = aString:gsub('', ''):gsub('', '')
<error descr="Type mismatch. Required: 'number' Found: 'string'">aNumber</error>, <error descr="Type mismatch. Required: 'string' Found: 'number'">aString</error> = <error descr="Result 1, type mismatch. Required: 'number' Found: 'string'"><error descr="Result 2, type mismatch. Required: 'string' Found: 'number'">aString:gsub('', ''):gsub('', '')</error></error>

0 comments on commit 54ace36

Please sign in to comment.