[MPP] Support multiple levels of actual type alias expansions

Commonizer might transform typealias chains into several
expect classes with actual type aliases. In this case
refining a common type once is not enough as the result
will be another expect type from type alias expansion.

KT-46691
This commit is contained in:
Pavel Kirpichenkov
2021-06-16 19:12:53 +03:00
committed by teamcityserver
parent d84cc4333c
commit 1f3004a667
@@ -65,15 +65,27 @@ class KotlinTypeRefinerImpl(
!type.needsRefinement() -> type
type.canBeCached() -> {
val cached = refinedTypeCache.computeIfAbsent(type.constructor) {
type.constructor.declarationDescriptor!!.defaultType.refine(this)
type.constructor.declarationDescriptor!!.defaultType.refineWithRespectToAbbreviatedTypes(this)
}
cached.restoreAdditionalTypeInformation(type)
}
else -> type.refine(this)
else -> type.refineWithRespectToAbbreviatedTypes(this)
}
}
private fun KotlinType.refineWithRespectToAbbreviatedTypes(refiner: KotlinTypeRefiner): KotlinType {
var previousRefinement: KotlinType
var currentRefinement: KotlinType = this
do {
previousRefinement = currentRefinement
currentRefinement = previousRefinement.refine(refiner)
} while (currentRefinement is AbbreviatedType && currentRefinement != previousRefinement)
return currentRefinement
}
private fun KotlinType.needsRefinement(): Boolean = isRefinementNeededForTypeConstructor(constructor)
private fun KotlinType.canBeCached(): Boolean = hasNotTrivialRefinementFactory && constructor.declarationDescriptor != null