From 45f5672b50661d6ce81bf171fe4707da25a9434f Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Tue, 23 Jan 2024 16:07:01 +0100 Subject: [PATCH] [FE] Reuse result of approximate calls in approximation of captured type #KTIJ-28549 Fixed --- .../kotlin/types/AbstractTypeApproximator.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/compiler/resolution.common/src/org/jetbrains/kotlin/types/AbstractTypeApproximator.kt b/compiler/resolution.common/src/org/jetbrains/kotlin/types/AbstractTypeApproximator.kt index e6a51ba63af..803078d6a12 100644 --- a/compiler/resolution.common/src/org/jetbrains/kotlin/types/AbstractTypeApproximator.kt +++ b/compiler/resolution.common/src/org/jetbrains/kotlin/types/AbstractTypeApproximator.kt @@ -319,6 +319,9 @@ abstract class AbstractTypeApproximator( } val baseSubType = type.lowerType() ?: nothingType() + val approximatedSuperType by lazy(LazyThreadSafetyMode.NONE) { approximateToSuperType(baseSuperType, conf, depth) } + val approximatedSubType by lazy(LazyThreadSafetyMode.NONE) { approximateToSubType(baseSubType, conf, depth) } + if (!conf.capturedType(ctx, type)) { /** * Here everything is ok if bounds for this captured type should not be approximated. @@ -328,15 +331,11 @@ abstract class AbstractTypeApproximator( * * todo handle flexible types */ - if (approximateToSuperType(baseSuperType, conf, depth) == null && approximateToSubType(baseSubType, conf, depth) == null) { + if (approximatedSuperType == null && approximatedSubType == null) { return null } } - val baseResult = if (toSuper) approximateToSuperType(baseSuperType, conf, depth) ?: baseSuperType else approximateToSubType( - baseSubType, - conf, - depth - ) ?: baseSubType + val baseResult = if (toSuper) approximatedSuperType ?: baseSuperType else approximatedSubType ?: baseSubType // C = in Int, Int <: C => Int? <: C? // C = out Number, C <: Number => C? <: Number?