[FIR] Add ability to get scopes for declarations of TYPES resolve phase

This commit is contained in:
Dmitriy Novozhilov
2020-09-28 11:57:46 +03:00
parent cc4f72e032
commit 8f1062594f
@@ -22,14 +22,20 @@ import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
fun ConeKotlinType.scope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope? { fun ConeKotlinType.scope(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope? =
scope(useSiteSession, scopeSession, FirResolvePhase.STATUS)
fun ConeKotlinType.scopeForStatusResolve(useSiteSession: FirSession, scopeSession: ScopeSession): FirTypeScope? =
scope(useSiteSession, scopeSession, FirResolvePhase.TYPES)
private fun ConeKotlinType.scope(useSiteSession: FirSession, scopeSession: ScopeSession, requiredPhase: FirResolvePhase): FirTypeScope? {
return when (this) { return when (this) {
is ConeKotlinErrorType -> null is ConeKotlinErrorType -> null
is ConeClassLikeType -> { is ConeClassLikeType -> {
val fullyExpandedType = fullyExpandedType(useSiteSession) val fullyExpandedType = fullyExpandedType(useSiteSession)
val fir = fullyExpandedType.lookupTag.toSymbol(useSiteSession)?.fir as? FirClass<*> ?: return null val fir = fullyExpandedType.lookupTag.toSymbol(useSiteSession)?.fir as? FirClass<*> ?: return null
fir.symbol.ensureResolved(FirResolvePhase.STATUS, useSiteSession) fir.symbol.ensureResolved(requiredPhase, useSiteSession)
val substitution = createSubstitution(fir.typeParameters, fullyExpandedType, useSiteSession) val substitution = createSubstitution(fir.typeParameters, fullyExpandedType, useSiteSession)
@@ -42,19 +48,19 @@ fun ConeKotlinType.scope(useSiteSession: FirSession, scopeSession: ScopeSession)
useSiteSession.typeContext, useSiteSession.typeContext,
symbol.fir.bounds.map { it.coneType } symbol.fir.bounds.map { it.coneType }
) )
intersectionType.scope(useSiteSession, scopeSession) ?: FirTypeScope.Empty intersectionType.scope(useSiteSession, scopeSession, requiredPhase) ?: FirTypeScope.Empty
} }
} }
is ConeRawType -> lowerBound.scope(useSiteSession, scopeSession) is ConeRawType -> lowerBound.scope(useSiteSession, scopeSession, requiredPhase)
is ConeFlexibleType -> lowerBound.scope(useSiteSession, scopeSession) is ConeFlexibleType -> lowerBound.scope(useSiteSession, scopeSession, requiredPhase)
is ConeIntersectionType -> FirTypeIntersectionScope.prepareIntersectionScope( is ConeIntersectionType -> FirTypeIntersectionScope.prepareIntersectionScope(
useSiteSession, useSiteSession,
FirStandardOverrideChecker(useSiteSession), FirStandardOverrideChecker(useSiteSession),
intersectedTypes.mapNotNullTo(mutableListOf()) { intersectedTypes.mapNotNullTo(mutableListOf()) {
it.scope(useSiteSession, scopeSession) it.scope(useSiteSession, scopeSession, requiredPhase)
} }
) )
is ConeDefinitelyNotNullType -> original.scope(useSiteSession, scopeSession) is ConeDefinitelyNotNullType -> original.scope(useSiteSession, scopeSession, requiredPhase)
is ConeIntegerLiteralType -> error("ILT should not be in receiver position") is ConeIntegerLiteralType -> error("ILT should not be in receiver position")
else -> null else -> null
} }