K2: drop unnecessary attributes when inferring declaration types
Related to KT-62578
This commit is contained in:
committed by
Space Team
parent
90eaf5f70f
commit
cebb6747e3
+12
-1
@@ -30,10 +30,21 @@ fun FirTypeRef.approximateDeclarationType(
|
||||
}
|
||||
|
||||
val preparedType = if (isLocal) baseType else baseType.substituteAlternativesInPublicType(session)
|
||||
val approximatedType = session.typeApproximator.approximateToSuperType(preparedType, configuration) ?: preparedType
|
||||
var approximatedType = session.typeApproximator.approximateToSuperType(preparedType, configuration) ?: preparedType
|
||||
if (approximatedType.contains { type -> type.attributes.any { !it.keepInInferredDeclarationType } }) {
|
||||
approximatedType = UnnecessaryAttributesRemover(session).substituteOrSelf(approximatedType)
|
||||
}
|
||||
return this.withReplacedConeType(approximatedType).applyIf(stripEnhancedNullability) { withoutEnhancedNullability() }
|
||||
}
|
||||
|
||||
private class UnnecessaryAttributesRemover(session: FirSession) : AbstractConeSubstitutor(session.typeContext) {
|
||||
override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
|
||||
val filteredAttributes = type.attributes.filterNecessaryToKeep()
|
||||
return if (filteredAttributes === type.attributes) null
|
||||
else type.withAttributes(filteredAttributes)
|
||||
}
|
||||
}
|
||||
|
||||
private fun ConeKotlinType.substituteAlternativesInPublicType(session: FirSession): ConeKotlinType {
|
||||
val substitutor = object : AbstractConeSubstitutor(session.typeContext) {
|
||||
override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
|
||||
|
||||
Reference in New Issue
Block a user