[NI] Fix substitution in completion of callable references in coroutine inference

This commit is contained in:
Dmitriy Novozhilov
2019-12-20 11:37:01 +03:00
parent 04d4366f2a
commit b54169d312
8 changed files with 80 additions and 5 deletions
@@ -237,4 +237,6 @@ class ComposedSubstitutor(val left: NewTypeSubstitutor, val right: NewTypeSubsti
right.substituteNotNullTypeWithConstructor(constructor)?.constructor ?: constructor
)
}
override val isEmpty: Boolean get() = left.isEmpty && right.isEmpty
}
@@ -264,15 +264,25 @@ class ResolvedAtomCompleter(
return
}
val resultTypeParameters =
callableCandidate.freshSubstitutor!!.freshVariables.map { resultSubstitutor.safeSubstitute(it.defaultType) }
callableCandidate.freshSubstitutor!!.freshVariables.map { resultSubstitutor.safeSubstitute(it.defaultType).asTypeProjection() }
val firstSubstitutor = IndexedParametersSubstitution(callableCandidate.candidate.typeParameters, resultTypeParameters)
val secondSubstitution = object : TypeSubstitution() {
override fun get(key: KotlinType): TypeProjection? {
return resultSubstitutor.safeSubstitute(key.unwrap()).takeIf { it !== key }?.asTypeProjection()
}
override fun isEmpty(): Boolean {
return resultSubstitutor.isEmpty
}
}
val resultSubstitutor = TypeSubstitutor.createChainedSubstitutor(
firstSubstitutor,
secondSubstitution
)
val psiCallArgument = resolvedAtom.atom.psiCallArgument as CallableReferenceKotlinCallArgumentImpl
val callableReferenceExpression = psiCallArgument.ktCallableReferenceExpression
val resultSubstitutor = IndexedParametersSubstitution(
callableCandidate.candidate.typeParameters,
resultTypeParameters.map { it.asTypeProjection() }).buildSubstitutor()
// write down type for callable reference expression
val resultType = resultSubstitutor.safeSubstitute(callableCandidate.reflectionCandidateType, Variance.INVARIANT)