From 1f3004a667e0b25b194ea8dd7f078f7cc1c1609a Mon Sep 17 00:00:00 2001 From: Pavel Kirpichenkov Date: Wed, 16 Jun 2021 19:12:53 +0300 Subject: [PATCH] [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 --- .../kotlin/types/KotlinTypeRefinerImpl.kt | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/KotlinTypeRefinerImpl.kt b/compiler/frontend/src/org/jetbrains/kotlin/types/KotlinTypeRefinerImpl.kt index fe63784aae2..c06b2c5de4d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/KotlinTypeRefinerImpl.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/KotlinTypeRefinerImpl.kt @@ -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