Resolution: extract projections from captured flexible type properly

#KT-54100 Fixed
Related to KT-54196, KT-54198
This commit is contained in:
Mikhail Glukhikh
2022-09-20 13:59:29 +02:00
committed by teamcity
parent 8517249776
commit e9bb0f4fda
12 changed files with 130 additions and 4 deletions
@@ -204,9 +204,15 @@ class VariableFixationFinder(
inline fun TypeSystemInferenceExtensionContext.isProperTypeForFixation(type: KotlinTypeMarker, isProper: (KotlinTypeMarker) -> Boolean) =
isProper(type) && extractProjectionsForAllCapturedTypes(type).all(isProper)
@OptIn(ExperimentalStdlibApi::class)
fun TypeSystemInferenceExtensionContext.extractProjectionsForAllCapturedTypes(baseType: KotlinTypeMarker): Set<KotlinTypeMarker> {
val simpleBaseType = baseType.asSimpleType()
if (baseType.isFlexible()) {
val flexibleType = baseType.asFlexibleType()!!
return buildSet {
addAll(extractProjectionsForAllCapturedTypes(flexibleType.lowerBound()))
addAll(extractProjectionsForAllCapturedTypes(flexibleType.upperBound()))
}
}
val simpleBaseType = baseType.asSimpleType()?.originalIfDefinitelyNotNullable()
return buildSet {
val projectionType = if (simpleBaseType is CapturedTypeMarker) {
@@ -289,7 +289,7 @@ class NewConstraintSystemImpl(
private fun isProperTypeImpl(type: KotlinTypeMarker): Boolean =
!type.contains {
val capturedType = it.asSimpleType()?.asCapturedType()
// TODO: change NewCapturedType to markered one for FE-IR
val typeToCheck = if (capturedType is CapturedTypeMarker && capturedType.captureStatus() == CaptureStatus.FROM_EXPRESSION)
capturedType.typeConstructorProjection().takeUnless { projection -> projection.isStarProjection() }?.getType()
else