FIR: fix substitution of anonymous type's supertype again

^KT-51418 Fixed
This commit is contained in:
pyos
2022-10-31 12:53:47 +01:00
committed by teamcity
parent f099c190f7
commit 7787638737
3 changed files with 17 additions and 39 deletions
@@ -416,46 +416,10 @@ private fun ConeKotlinType.approximateToOnlySupertype(session: FirSession): Cone
return null
}
val result = superType.type.withNullability(nullability, session.typeContext)
if (typeArguments.isNotEmpty()) {
val substitution = mutableMapOf<FirTypeParameterSymbol, ConeKotlinType>()
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
if (typeArguments.isNotEmpty() && typeArguments.size == firClass.typeParameters.size) {
val substitution = firClass.typeParameters.zip(typeArguments).associate { (parameter, argument) ->
parameter.symbol to argument.type!!
}
addSubstitution(result)
return ConeSubstitutorByMap(substitution, session).substituteOrSelf(result)
}
return result
@@ -31,13 +31,18 @@ class FieldTest {
interface I<T>
interface I2<A, B>
interface I3<T> { fun foo(x: T) }
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>> {}
private fun <V, W> I3<V>.f4(block: (W) -> V) = object : I3<W> {
override fun foo(x: W) = this@f4.foo(block(x))
}
fun g() = f("f")
fun g1() = f("f1")
fun g2() = f2("f2")
fun g3() = f3("f3", 3)
fun <V, W> I3<V>.g4(block: (W) -> V) = f4(block)
@@ -12,6 +12,8 @@ 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>
private fun </*0*/ V, /*1*/ W> I3<V>.f4(/*0*/ block: (W) -> V): f4.`<no name provided>`<V, W>
public fun </*0*/ V, /*1*/ W> I3<V>.g4(/*0*/ block: (W) -> V): I3<W>
public abstract class A</*0*/ T> {
public constructor A</*0*/ T>()
@@ -43,3 +45,10 @@ public interface I2</*0*/ A, /*1*/ B> {
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface I3</*0*/ T> {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public abstract fun foo(/*0*/ x: T): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}