FIR: Support substitution of inner class constructor capturing outer type parameters
This commit is contained in:
committed by
teamcityserver
parent
91806c0a68
commit
9c7982673b
+7
-10
@@ -472,8 +472,8 @@ object FirFakeOverrideGenerator {
|
|||||||
forceTypeParametersRecreation: Boolean = true
|
forceTypeParametersRecreation: Boolean = true
|
||||||
): Pair<List<FirTypeParameterRef>, ConeSubstitutor> {
|
): Pair<List<FirTypeParameterRef>, ConeSubstitutor> {
|
||||||
if (member.typeParameters.isEmpty()) return Pair(member.typeParameters, substitutor)
|
if (member.typeParameters.isEmpty()) return Pair(member.typeParameters, substitutor)
|
||||||
val newTypeParameters = member.typeParameters.map { typeParameter ->
|
val newTypeParameters = member.typeParameters.map { typeParameterRef ->
|
||||||
if (typeParameter !is FirTypeParameter) return@map null
|
val typeParameter = typeParameterRef.symbol.fir
|
||||||
FirTypeParameterBuilder().apply {
|
FirTypeParameterBuilder().apply {
|
||||||
source = typeParameter.source
|
source = typeParameter.source
|
||||||
moduleData = typeParameter.moduleData
|
moduleData = typeParameter.moduleData
|
||||||
@@ -486,18 +486,15 @@ object FirFakeOverrideGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val substitutionMapForNewParameters = member.typeParameters.zip(newTypeParameters).mapNotNull { (original, new) ->
|
val substitutionMapForNewParameters = member.typeParameters.zip(newTypeParameters).associate { (original, new) ->
|
||||||
if (new != null)
|
Pair(original.symbol, ConeTypeParameterTypeImpl(new.symbol.toLookupTag(), isNullable = false))
|
||||||
Pair(original.symbol, ConeTypeParameterTypeImpl(new.symbol.toLookupTag(), isNullable = false))
|
}
|
||||||
else null
|
|
||||||
}.toMap()
|
|
||||||
|
|
||||||
val additionalSubstitutor = substitutorByMap(substitutionMapForNewParameters, useSiteSession)
|
val additionalSubstitutor = substitutorByMap(substitutionMapForNewParameters, useSiteSession)
|
||||||
|
|
||||||
var wereChangesInTypeParameters = forceTypeParametersRecreation
|
var wereChangesInTypeParameters = forceTypeParametersRecreation
|
||||||
for ((newTypeParameter, oldTypeParameter) in newTypeParameters.zip(member.typeParameters)) {
|
for ((newTypeParameter, oldTypeParameter) in newTypeParameters.zip(member.typeParameters)) {
|
||||||
if (newTypeParameter == null) continue
|
val original = oldTypeParameter.symbol.fir
|
||||||
val original = oldTypeParameter as FirTypeParameter
|
|
||||||
for (boundTypeRef in original.bounds) {
|
for (boundTypeRef in original.bounds) {
|
||||||
val typeForBound = boundTypeRef.coneType
|
val typeForBound = boundTypeRef.coneType
|
||||||
val substitutedBound = substitutor.substituteOrNull(typeForBound)
|
val substitutedBound = substitutor.substituteOrNull(typeForBound)
|
||||||
@@ -514,7 +511,7 @@ object FirFakeOverrideGenerator {
|
|||||||
|
|
||||||
if (!wereChangesInTypeParameters) return Pair(member.typeParameters, substitutor)
|
if (!wereChangesInTypeParameters) return Pair(member.typeParameters, substitutor)
|
||||||
return Pair(
|
return Pair(
|
||||||
newTypeParameters.mapIndexed { index, builder -> builder?.build() ?: member.typeParameters[index] },
|
newTypeParameters.map(FirTypeParameterBuilder::build),
|
||||||
ChainedSubstitutor(substitutor, additionalSubstitutor)
|
ChainedSubstitutor(substitutor, additionalSubstitutor)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user