[NI] Update lambda result types.

When completing calls, update return types for functional descriptors
for lambdas using type inference results.

Add toString to some Call subclasses (for debugging purposes).
This commit is contained in:
Dmitry Petrov
2017-04-25 11:57:55 +03:00
committed by Stanislav Erokhin
parent 2bf252afe6
commit 1d6ed4ef8e
9 changed files with 46 additions and 17 deletions
@@ -102,7 +102,7 @@ class KotlinCallResolver(
}
return maximallySpecificCandidates.map {
kotlinCallCompleter.transformWhenAmbiguity(it)
kotlinCallCompleter.transformWhenAmbiguity(it, callContext.lambdaAnalyzer)
}
}
}
@@ -17,10 +17,8 @@
package org.jetbrains.kotlin.resolve.calls.components
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.resolve.calls.model.KotlinCall
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallArgument
import org.jetbrains.kotlin.resolve.calls.model.KotlinResolutionCandidate
import org.jetbrains.kotlin.resolve.calls.model.LambdaKotlinCallArgument
import org.jetbrains.kotlin.resolve.calls.model.*
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.UnwrappedType
interface IsDescriptorFromSourcePredicate: (CallableDescriptor) -> Boolean
@@ -39,4 +37,6 @@ interface LambdaAnalyzer {
// todo this is hack for some client which try to read ResolvedCall from trace before all calls completed
fun bindStubResolvedCallForCandidate(candidate: KotlinResolutionCandidate)
fun completeLambdaReturnType(lambdaArgument: ResolvedLambdaArgument, returnType: KotlinType)
}
@@ -63,8 +63,8 @@ class KotlinCallCompleter(
fun getBuilder(): ConstraintSystemBuilder
}
fun transformWhenAmbiguity(candidate: KotlinResolutionCandidate): ResolvedKotlinCall =
toCompletedBaseResolvedCall(candidate.lastCall.constraintSystem.asCallCompleterContext(), candidate)
fun transformWhenAmbiguity(candidate: KotlinResolutionCandidate, lambdaAnalyzer: LambdaAnalyzer): ResolvedKotlinCall =
toCompletedBaseResolvedCall(candidate.lastCall.constraintSystem.asCallCompleterContext(), candidate, lambdaAnalyzer)
fun completeCallIfNecessary(
candidate: KotlinResolutionCandidate,
@@ -82,7 +82,7 @@ class KotlinCallCompleter(
val c = candidate.lastCall.constraintSystem.asCallCompleterContext()
topLevelCall.competeCall(c, lambdaAnalyzer)
return toCompletedBaseResolvedCall(c, candidate)
return toCompletedBaseResolvedCall(c, candidate, lambdaAnalyzer)
}
return ResolvedKotlinCall.OnlyResolvedKotlinCall(candidate)
@@ -90,13 +90,17 @@ class KotlinCallCompleter(
private fun toCompletedBaseResolvedCall(
c: Context,
candidate: KotlinResolutionCandidate
candidate: KotlinResolutionCandidate,
lambdaAnalyzer: LambdaAnalyzer
): ResolvedKotlinCall.CompletedResolvedKotlinCall {
val currentSubstitutor = c.buildResultingSubstitutor()
val completedCall = candidate.toCompletedCall(currentSubstitutor)
val competedCalls = c.innerCalls.map {
it.candidate.toCompletedCall(currentSubstitutor)
}
c.lambdaArguments.forEach {
lambdaAnalyzer.completeLambdaReturnType(it, currentSubstitutor.safeSubstitute(it.returnType))
}
return ResolvedKotlinCall.CompletedResolvedKotlinCall(completedCall, competedCalls)
}