[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
|
||||
|
||||
+14
-1
@@ -27,4 +27,17 @@ class FieldTest {
|
||||
|
||||
private val ttt = test.bar()
|
||||
private val qqq = ttt.qux()
|
||||
}
|
||||
}
|
||||
|
||||
interface I<T>
|
||||
interface I2<A, B>
|
||||
|
||||
private fun <V> f(x: V) = object : I<I<V>> {}
|
||||
private fun <V> f1(x: V) = object : I<I<in V>> {}
|
||||
private fun <V> f2(x: V) = object : I2<V, V> {}
|
||||
private fun <V, W> f3(x: V, y: W) = object : I<I2<*, W>> {}
|
||||
|
||||
fun g() = f("f")
|
||||
fun g1() = f("f1")
|
||||
fun g2() = f2("f2")
|
||||
fun g3() = f3("f3", 3)
|
||||
|
||||
+20
@@ -1,7 +1,15 @@
|
||||
package
|
||||
|
||||
private fun </*0*/ V> f(/*0*/ x: V): f.`<no name provided>`<V>
|
||||
private fun </*0*/ V> f1(/*0*/ x: V): f1.`<no name provided>`<V>
|
||||
private fun </*0*/ V> f2(/*0*/ x: V): f2.`<no name provided>`<V>
|
||||
private fun </*0*/ V, /*1*/ W> f3(/*0*/ x: V, /*1*/ y: W): f3.`<no name provided>`<V, W>
|
||||
private fun fPrivate(): test.`<no name provided>`<kotlin.String>
|
||||
public fun fPublic(): A<kotlin.String>
|
||||
public fun g(): I<I<kotlin.String>>
|
||||
public fun g1(): I<I<kotlin.String>>
|
||||
public fun g2(): I2<kotlin.String, kotlin.String>
|
||||
public fun g3(): I<I2<*, kotlin.Int>>
|
||||
public fun main(): kotlin.Unit
|
||||
private fun </*0*/ T> test(/*0*/ t: T): test.`<no name provided>`<T>
|
||||
|
||||
@@ -23,3 +31,15 @@ public final class FieldTest {
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public interface I</*0*/ T> {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public interface I2</*0*/ A, /*1*/ B> {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user