[FIR] Use captureFromArguments in createSubstitution
This commit breaks ~57 resolve tests because captured types now exists at the end of FIR resolve
This commit is contained in:
@@ -32,7 +32,7 @@ fun ConeKotlinType.scope(useSiteSession: FirSession, scopeSession: ScopeSession)
|
|||||||
|
|
||||||
fir.symbol.ensureResolved(FirResolvePhase.STATUS, useSiteSession)
|
fir.symbol.ensureResolved(FirResolvePhase.STATUS, useSiteSession)
|
||||||
|
|
||||||
val substitution = createSubstitution(fir.typeParameters, fullyExpandedType.typeArguments, useSiteSession)
|
val substitution = createSubstitution(fir.typeParameters, fullyExpandedType, useSiteSession)
|
||||||
|
|
||||||
fir.scope(substitutorByMap(substitution), useSiteSession, scopeSession, skipPrivateMembers = false)
|
fir.scope(substitutorByMap(substitution), useSiteSession, scopeSession, skipPrivateMembers = false)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.*
|
|||||||
import org.jetbrains.kotlin.fir.typeContext
|
import org.jetbrains.kotlin.fir.typeContext
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
|
import org.jetbrains.kotlin.types.model.CaptureStatus
|
||||||
|
|
||||||
abstract class SupertypeSupplier {
|
abstract class SupertypeSupplier {
|
||||||
abstract fun forClass(firClass: FirClass<*>): List<ConeClassLikeType>
|
abstract fun forClass(firClass: FirClass<*>): List<ConeClassLikeType>
|
||||||
@@ -63,9 +64,11 @@ data class SubstitutionScopeKey(val type: ConeClassLikeType) : ScopeSessionKey<F
|
|||||||
/* TODO REMOVE */
|
/* TODO REMOVE */
|
||||||
fun createSubstitution(
|
fun createSubstitution(
|
||||||
typeParameters: List<FirTypeParameterRef>, // TODO: or really declared?
|
typeParameters: List<FirTypeParameterRef>, // TODO: or really declared?
|
||||||
typeArguments: Array<out ConeTypeProjection>,
|
type: ConeClassLikeType,
|
||||||
session: FirSession
|
session: FirSession
|
||||||
): Map<FirTypeParameterSymbol, ConeKotlinType> {
|
): Map<FirTypeParameterSymbol, ConeKotlinType> {
|
||||||
|
val capturedOrType = session.typeContext.captureFromArguments(type, CaptureStatus.FOR_SUBTYPING) ?: type
|
||||||
|
val typeArguments = (capturedOrType as ConeClassLikeType).typeArguments
|
||||||
return typeParameters.zip(typeArguments) { typeParameter, typeArgument ->
|
return typeParameters.zip(typeArguments) { typeParameter, typeArgument ->
|
||||||
val typeParameterSymbol = typeParameter.symbol
|
val typeParameterSymbol = typeParameter.symbol
|
||||||
typeParameterSymbol to when (typeArgument) {
|
typeParameterSymbol to when (typeArgument) {
|
||||||
@@ -92,14 +95,14 @@ fun ConeClassLikeType.wrapSubstitutionScopeIfNeed(
|
|||||||
if (this.typeArguments.isEmpty()) return useSiteMemberScope
|
if (this.typeArguments.isEmpty()) return useSiteMemberScope
|
||||||
return builder.getOrBuild(declaration.symbol, SubstitutionScopeKey(this)) {
|
return builder.getOrBuild(declaration.symbol, SubstitutionScopeKey(this)) {
|
||||||
val typeParameters = (declaration as? FirTypeParameterRefsOwner)?.typeParameters.orEmpty()
|
val typeParameters = (declaration as? FirTypeParameterRefsOwner)?.typeParameters.orEmpty()
|
||||||
val originalSubstitution = createSubstitution(typeParameters, typeArguments, session)
|
val originalSubstitution = createSubstitution(typeParameters, this, session)
|
||||||
val platformClass = session.platformClassMapper.getCorrespondingPlatformClass(declaration)
|
val platformClass = session.platformClassMapper.getCorrespondingPlatformClass(declaration)
|
||||||
if (platformClass != null) {
|
if (platformClass != null) {
|
||||||
// This kind of substitution is necessary when method which is mapped from Java (e.g. Java Map.forEach)
|
// This kind of substitution is necessary when method which is mapped from Java (e.g. Java Map.forEach)
|
||||||
// is called on an external type, like MyMap<String, String>,
|
// is called on an external type, like MyMap<String, String>,
|
||||||
// to determine parameter types properly (e.g. String, String instead of K, V)
|
// to determine parameter types properly (e.g. String, String instead of K, V)
|
||||||
val platformTypeParameters = platformClass.typeParameters
|
val platformTypeParameters = platformClass.typeParameters
|
||||||
val platformSubstitution = createSubstitution(platformTypeParameters, typeArguments, session)
|
val platformSubstitution = createSubstitution(platformTypeParameters, this, session)
|
||||||
FirClassSubstitutionScope(
|
FirClassSubstitutionScope(
|
||||||
session, useSiteMemberScope, builder, originalSubstitution + platformSubstitution,
|
session, useSiteMemberScope, builder, originalSubstitution + platformSubstitution,
|
||||||
skipPrivateMembers = true, derivedClassId = derivedClassId
|
skipPrivateMembers = true, derivedClassId = derivedClassId
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ class KotlinScopeProvider(
|
|||||||
|
|
||||||
private fun substitutor(symbol: FirRegularClassSymbol, type: ConeClassLikeType, useSiteSession: FirSession): ConeSubstitutor {
|
private fun substitutor(symbol: FirRegularClassSymbol, type: ConeClassLikeType, useSiteSession: FirSession): ConeSubstitutor {
|
||||||
if (type.typeArguments.isEmpty()) return ConeSubstitutor.Empty
|
if (type.typeArguments.isEmpty()) return ConeSubstitutor.Empty
|
||||||
val originalSubstitution = createSubstitution(symbol.fir.typeParameters, type.typeArguments, useSiteSession)
|
val originalSubstitution = createSubstitution(symbol.fir.typeParameters, type, useSiteSession)
|
||||||
return substitutorByMap(originalSubstitution)
|
return substitutorByMap(originalSubstitution)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user