[FIR] Fix substitution of anonymous type's supertypes, ^KT-51418 Fixed
This commit is contained in:
committed by
Space Team
parent
c5732b6f4d
commit
9c6df5313a
@@ -411,16 +411,42 @@ private fun ConeKotlinType.approximateToOnlySupertype(session: FirSession): Cone
|
||||
return null
|
||||
}
|
||||
val result = superType.type.withNullability(nullability, session.typeContext)
|
||||
val resultTypeArguments = result.typeArguments
|
||||
if (resultTypeArguments.isNotEmpty() && resultTypeArguments.size == typeArguments.size) {
|
||||
if (typeArguments.isNotEmpty()) {
|
||||
val substitution = mutableMapOf<FirTypeParameterSymbol, ConeKotlinType>()
|
||||
for (index in resultTypeArguments.indices) {
|
||||
// TODO: this is not correct (should use firClass' arguments as keys); see comment in KT-51418
|
||||
val key = resultTypeArguments[index]
|
||||
val value = typeArguments[index]
|
||||
val symbol = (key as? ConeTypeParameterType)?.lookupTag?.typeParameterSymbol ?: continue
|
||||
substitution[symbol] = value.type!!
|
||||
|
||||
var index = 0
|
||||
fun addSubstitution(projection: ConeTypeProjection): Boolean {
|
||||
when (projection) {
|
||||
is ConeTypeParameterType -> {
|
||||
val symbol = projection.lookupTag.typeParameterSymbol
|
||||
if (!substitution.containsKey(symbol)) {
|
||||
substitution[symbol] = typeArguments[index].type!!
|
||||
index++
|
||||
}
|
||||
}
|
||||
is ConeErrorType -> {
|
||||
return false
|
||||
}
|
||||
is ConeClassLikeType -> {
|
||||
for (typeArgument in projection.typeArguments) {
|
||||
if (!addSubstitution(typeArgument)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
is ConeKotlinTypeProjection -> {
|
||||
if (!addSubstitution(projection.type)) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
is ConeStarProjection -> {
|
||||
index++
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
addSubstitution(result)
|
||||
return ConeSubstitutorByMap(substitution, session).substituteOrSelf(result)
|
||||
}
|
||||
return result
|
||||
|
||||
Reference in New Issue
Block a user