From c1925885fe50ce16b25fafe246e04a574414a498 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Thu, 17 Feb 2022 15:20:47 +0300 Subject: [PATCH] Extract ConeTypeSubstitutorByTypeConstructor --- .../fir/resolve/substitution/Substitutors.kt | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt index 600b6767c03..76657f3e59e 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt @@ -223,24 +223,19 @@ fun createTypeSubstitutorByTypeConstructor( approximateIntegerLiterals: Boolean ): ConeSubstitutor { if (map.isEmpty()) return ConeSubstitutor.Empty - return object : AbstractConeSubstitutor(context), TypeSubstitutorMarker { - override fun substituteType(type: ConeKotlinType): ConeKotlinType? { - if (type !is ConeLookupTagBasedType && type !is ConeStubType) return null - val new = map[type.typeConstructor(context)] ?: return null - val approximatedIntegerLiteralType = if (approximateIntegerLiterals) new.approximateIntegerLiteralType() else new - return approximatedIntegerLiteralType.updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type) - } - } + return ConeTypeSubstitutorByTypeConstructor(map, context, approximateIntegerLiterals) } -internal class TypeSubstitutorByTypeConstructor( +internal class ConeTypeSubstitutorByTypeConstructor( private val map: Map, - context: ConeTypeContext + private val context: ConeTypeContext, + private val approximateIntegerLiterals: Boolean ) : AbstractConeSubstitutor(context), TypeSubstitutorMarker { override fun substituteType(type: ConeKotlinType): ConeKotlinType? { if (type !is ConeLookupTagBasedType && type !is ConeStubType) return null - val new = map[type.typeConstructor(typeContext)] ?: return null - return new.approximateIntegerLiteralType().updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type) + val new = map[type.typeConstructor(context)] ?: return null + val approximatedIntegerLiteralType = if (approximateIntegerLiterals) new.approximateIntegerLiteralType() else new + return approximatedIntegerLiteralType.updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type) } }