diff --git a/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt b/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt index 4aa391bd2a3..7dd176f86c7 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/types/TypeApproximator.kt @@ -206,10 +206,12 @@ class TypeApproximator { val baseResult = when (conf.intersection) { ALLOWED -> if (!thereIsApproximation) return null else intersectTypes(newTypes) TO_FIRST -> if (toSuper) newTypes.first() else return type.defaultResult(toSuper = false) - // commonSupertypeCalculator should handle flexible types correctly - TO_COMMON_SUPERTYPE -> if (toSuper) NewCommonSuperTypeCalculator.commonSuperType(newTypes) else return type.defaultResult( - toSuper = false - ) + // commonSupertypeCalculator should handle flexible types correctly + TO_COMMON_SUPERTYPE -> { + if (!toSuper) return type.defaultResult(toSuper = false) + val resultType = NewCommonSuperTypeCalculator.commonSuperType(newTypes) + approximateToSuperType(resultType.unwrap(), conf) ?: resultType.unwrap() + } } return if (type.isMarkedNullable) baseResult.makeNullableAsSpecified(true) else baseResult