Wire proper KotlinTypeRefiner into ClassicTypeSystemCotextForCS

^KT-48589 Fixed
This commit is contained in:
Dmitry Savvinov
2021-09-03 18:19:46 +03:00
parent 9e50f40586
commit d6cb96aa24
8 changed files with 42 additions and 19 deletions
@@ -63,7 +63,7 @@ class BuilderInferenceSession(
private var nestedBuilderInferenceSessions: MutableSet<BuilderInferenceSession> = mutableSetOf()
private lateinit var lambda: ResolvedLambdaAtom
private val commonSystem = NewConstraintSystemImpl(callComponents.constraintInjector, builtIns)
private val commonSystem = NewConstraintSystemImpl(callComponents.constraintInjector, builtIns, callComponents.kotlinTypeRefiner)
init {
if (topLevelCallContext.inferenceSession is BuilderInferenceSession) {
@@ -40,12 +40,15 @@ import org.jetbrains.kotlin.resolve.calls.model.SimpleKotlinCallArgument
import org.jetbrains.kotlin.resolve.calls.results.SimpleConstraintSystem
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.KotlinTypeRefinerImpl
import org.jetbrains.kotlin.types.TypeIntersector
import org.jetbrains.kotlin.types.checker.KotlinTypeRefiner
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
class KotlinResolutionStatelessCallbacksImpl(
private val deprecationResolver: DeprecationResolver,
private val languageVersionSettings: LanguageVersionSettings,
private val kotlinTypeRefiner: KotlinTypeRefiner
) : KotlinResolutionStatelessCallbacks {
override fun isDescriptorFromSource(descriptor: CallableDescriptor) =
DescriptorToSourceUtils.descriptorToDeclaration(descriptor) != null
@@ -107,10 +110,10 @@ class KotlinResolutionStatelessCallbacksImpl(
}
override fun createConstraintSystemForOverloadResolution(
constraintInjector: ConstraintInjector, builtIns: KotlinBuiltIns,
constraintInjector: ConstraintInjector, builtIns: KotlinBuiltIns
): SimpleConstraintSystem {
return if (languageVersionSettings.getFlag(AnalysisFlags.constraintSystemForOverloadResolution).forNewInference())
SimpleConstraintSystemImpl(constraintInjector, builtIns)
SimpleConstraintSystemImpl(constraintInjector, builtIns, kotlinTypeRefiner)
else
ConstraintSystemBuilderImpl.forSpecificity()
}
@@ -109,7 +109,7 @@ abstract class ManyCandidatesResolver<D : CallableDescriptor>(
for (callInfo in listOf(goodCandidate, badCandidate)) {
val atomsToAnalyze = mutableListOf<ResolvedAtom>(callInfo.callResolutionResult)
val system = NewConstraintSystemImpl(callComponents.constraintInjector, builtIns).apply {
val system = NewConstraintSystemImpl(callComponents.constraintInjector, builtIns, callComponents.kotlinTypeRefiner).apply {
addOtherSystem(callInfo.callResolutionResult.constraintSystem)
/*
* This is needed for very stupid case, when we have some delegate with good `getValue` and bad `setValue` that
@@ -144,7 +144,7 @@ abstract class ManyCandidatesResolver<D : CallableDescriptor>(
)
}
} else {
val commonSystem = NewConstraintSystemImpl(callComponents.constraintInjector, builtIns).apply {
val commonSystem = NewConstraintSystemImpl(callComponents.constraintInjector, builtIns, callComponents.kotlinTypeRefiner).apply {
addOtherSystem(currentConstraintSystem())
}