[FIR] CustomAnnotationTypeAttribute: drop containerSymbols
Now annotations have the container symbol itself, so this property is no longer needed. This migration fixes issues with a missed container symbol, so now all cases of lazy resolution from KtType are supported ^KT-63042
This commit is contained in:
committed by
Space Team
parent
264a151676
commit
83bdac8d61
@@ -7,7 +7,6 @@ package org.jetbrains.kotlin.fir
|
||||
|
||||
import org.jetbrains.kotlin.KtSourceElement
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.expandedConeType
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.expressions.builder.FirImplicitInvokeCallBuilder
|
||||
@@ -72,7 +71,6 @@ fun FirTypeRef.resolvedTypeFromPrototype(
|
||||
fun List<FirAnnotation>.computeTypeAttributes(
|
||||
session: FirSession,
|
||||
predefined: List<ConeAttribute<*>> = emptyList(),
|
||||
containerDeclaration: FirDeclaration? = null,
|
||||
allowExtensionFunctionType: Boolean = true,
|
||||
shouldExpandTypeAliases: Boolean
|
||||
): ConeAttributes {
|
||||
@@ -115,7 +113,7 @@ fun List<FirAnnotation>.computeTypeAttributes(
|
||||
}
|
||||
|
||||
if (customAnnotations.isNotEmpty()) {
|
||||
attributes += CustomAnnotationTypeAttribute(customAnnotations, containerDeclaration?.symbol)
|
||||
attributes += CustomAnnotationTypeAttribute(customAnnotations)
|
||||
}
|
||||
|
||||
return ConeAttributes.create(attributes)
|
||||
|
||||
+2
-10
@@ -222,7 +222,6 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
|
||||
result: TypeResolutionResult,
|
||||
areBareTypesAllowed: Boolean,
|
||||
topContainer: FirDeclaration?,
|
||||
containerDeclaration: FirDeclaration?,
|
||||
isOperandOfIsOperator: Boolean
|
||||
): ConeKotlinType {
|
||||
val (symbol, substitutor) = when (result) {
|
||||
@@ -284,7 +283,6 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
|
||||
typeRef.isMarkedNullable,
|
||||
typeRef.annotations.computeTypeAttributes(
|
||||
session,
|
||||
containerDeclaration = containerDeclaration,
|
||||
shouldExpandTypeAliases = true,
|
||||
allowExtensionFunctionType = (symbol.toLookupTag() as? ConeClassLikeLookupTag)?.isSomeFunctionType(session) == true,
|
||||
)
|
||||
@@ -373,10 +371,7 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
|
||||
return null
|
||||
}
|
||||
|
||||
private fun createFunctionType(
|
||||
typeRef: FirFunctionTypeRef,
|
||||
containerDeclaration: FirDeclaration? = null
|
||||
): FirTypeResolutionResult {
|
||||
private fun createFunctionType(typeRef: FirFunctionTypeRef): FirTypeResolutionResult {
|
||||
val parameters =
|
||||
typeRef.contextReceiverTypeRefs.map { it.coneType } +
|
||||
listOfNotNull(typeRef.receiverTypeRef?.coneType) +
|
||||
@@ -406,7 +401,6 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
|
||||
add(CompilerConeAttributes.ContextFunctionTypeParams(typeRef.contextReceiverTypeRefs.size))
|
||||
}
|
||||
},
|
||||
containerDeclaration,
|
||||
shouldExpandTypeAliases = true
|
||||
)
|
||||
return FirTypeResolutionResult(
|
||||
@@ -438,16 +432,14 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() {
|
||||
result,
|
||||
areBareTypesAllowed,
|
||||
scopeClassDeclaration.topContainer ?: scopeClassDeclaration.containingDeclarations.lastOrNull(),
|
||||
scopeClassDeclaration.containerDeclaration,
|
||||
isOperandOfIsOperator,
|
||||
)
|
||||
FirTypeResolutionResult(resolvedType, (result as? TypeResolutionResult.Resolved)?.typeCandidate?.diagnostic)
|
||||
}
|
||||
is FirFunctionTypeRef -> createFunctionType(typeRef, scopeClassDeclaration.containerDeclaration)
|
||||
is FirFunctionTypeRef -> createFunctionType(typeRef)
|
||||
is FirDynamicTypeRef -> {
|
||||
val attributes = typeRef.annotations.computeTypeAttributes(
|
||||
session,
|
||||
containerDeclaration = scopeClassDeclaration.containerDeclaration,
|
||||
shouldExpandTypeAliases = true
|
||||
)
|
||||
FirTypeResolutionResult(ConeDynamicType.create(session, attributes), diagnostic = null)
|
||||
|
||||
+2
-31
@@ -8,45 +8,16 @@ package org.jetbrains.kotlin.fir.types
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
|
||||
import org.jetbrains.kotlin.fir.render
|
||||
import org.jetbrains.kotlin.fir.renderer.FirRenderer
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
/**
|
||||
* @param containerSymbols a list of symbols that should be resolved to make [annotations] are fully resolved.
|
||||
* Required only for "lazy" resolve mode in AA FIR to make a type annotation lazily resolved.
|
||||
* See KtFirAnnotationListForType for reference.
|
||||
* Example:
|
||||
* ```kotlin
|
||||
* fun foo(): @Anno Type
|
||||
* ```
|
||||
* This `Anno` annotation will have `foo` function as [containerSymbols].
|
||||
* More than one [containerSymbols] possible in case of type aliases:
|
||||
* ```kotlin
|
||||
* interface BaseInterface
|
||||
* typealias FirstTypeAlias = @Anno1 BaseInterface
|
||||
* typealias SecondTypeAlias = @Anno2 FirstTypeAlias
|
||||
*
|
||||
* fun foo(): @Anno3 SecondTypeAlias = TODO()
|
||||
* ```
|
||||
* here `@Anno3 SecondTypeAlias` will be expanded to ` @Anno1 @Anno2 @Anno3 BaseInterface`
|
||||
* and will have all intermediate type-aliases as [containerSymbols].
|
||||
*/
|
||||
class CustomAnnotationTypeAttribute(
|
||||
val annotations: List<FirAnnotation>,
|
||||
val containerSymbols: List<FirBasedSymbol<*>> = emptyList(),
|
||||
) : ConeAttribute<CustomAnnotationTypeAttribute>() {
|
||||
constructor(annotations: List<FirAnnotation>, containerSymbol: FirBasedSymbol<*>?) : this(
|
||||
annotations,
|
||||
listOfNotNull(containerSymbol),
|
||||
)
|
||||
|
||||
class CustomAnnotationTypeAttribute(val annotations: List<FirAnnotation>) : ConeAttribute<CustomAnnotationTypeAttribute>() {
|
||||
override fun union(other: CustomAnnotationTypeAttribute?): CustomAnnotationTypeAttribute? = null
|
||||
|
||||
override fun intersect(other: CustomAnnotationTypeAttribute?): CustomAnnotationTypeAttribute? = null
|
||||
|
||||
override fun add(other: CustomAnnotationTypeAttribute?): CustomAnnotationTypeAttribute {
|
||||
if (other == null || other === this) return this
|
||||
return CustomAnnotationTypeAttribute(annotations + other.annotations, containerSymbols + other.containerSymbols)
|
||||
return CustomAnnotationTypeAttribute(annotations + other.annotations)
|
||||
}
|
||||
|
||||
override fun isSubtypeOf(other: CustomAnnotationTypeAttribute?): Boolean = true
|
||||
|
||||
Reference in New Issue
Block a user