FIR: Preserve non-custom attributes after substitution

The test is being fixed since synthetic call for elvis has @Exact-attribute on return type
This commit is contained in:
Denis.Zharkov
2021-11-15 16:11:12 +03:00
committed by teamcityserver
parent e26abbbbb0
commit 883b18a0c6
27 changed files with 239 additions and 185 deletions
@@ -100,15 +100,15 @@ fun ConeKotlinType.withParameterNameAnnotation(valueParameter: FirValueParameter
}
val attributesWithParameterNameAnnotation =
ConeAttributes.create(listOf(CustomAnnotationTypeAttribute(listOf(parameterNameAnnotationCall))))
return withCombinedCustomAttributesFrom(attributesWithParameterNameAnnotation, context)
return withCombinedAttributesFrom(attributesWithParameterNameAnnotation, context)
}
fun ConeKotlinType.withCombinedCustomAttributesFrom(other: ConeKotlinType, context: ConeTypeContext): ConeKotlinType =
withCombinedCustomAttributesFrom(other.attributes, context)
fun ConeKotlinType.withCombinedAttributesFrom(other: ConeKotlinType, context: ConeTypeContext): ConeKotlinType =
withCombinedAttributesFrom(other.attributes, context)
private fun ConeKotlinType.withCombinedCustomAttributesFrom(other: ConeAttributes, context: ConeTypeContext): ConeKotlinType {
val customAttributesFromOther = other.custom ?: return this
val combinedConeAttributes = attributes.add(ConeAttributes.create(listOf(customAttributesFromOther)))
private fun ConeKotlinType.withCombinedAttributesFrom(other: ConeAttributes, context: ConeTypeContext): ConeKotlinType {
if (other.isEmpty()) return this
val combinedConeAttributes = attributes.add(other)
return withAttributes(combinedConeAttributes, context)
}
@@ -6,7 +6,7 @@
package org.jetbrains.kotlin.fir.resolve.substitution
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.resolve.withCombinedCustomAttributesFrom
import org.jetbrains.kotlin.fir.resolve.withCombinedAttributesFrom
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
@@ -165,7 +165,7 @@ data class ConeSubstitutorByMap(
if (type !is ConeTypeParameterType) return null
val result =
substitution[type.lookupTag.symbol].updateNullabilityIfNeeded(type)
?.withCombinedCustomAttributesFrom(type, useSiteSession.typeContext)
?.withCombinedAttributesFrom(type, useSiteSession.typeContext)
?: return null
if (type.isUnsafeVarianceType(useSiteSession)) {
return useSiteSession.typeApproximator.approximateToSuperType(
@@ -182,7 +182,7 @@ fun createTypeSubstitutorByTypeConstructor(map: Map<TypeConstructorMarker, ConeK
override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
if (type !is ConeLookupTagBasedType && type !is ConeStubType) return null
val new = map[type.typeConstructor(context)] ?: return null
return new.approximateIntegerLiteralType().updateNullabilityIfNeeded(type)?.withCombinedCustomAttributesFrom(type, context)
return new.approximateIntegerLiteralType().updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type, context)
}
}
}