[FIR] Fix non-serializable type argument at the end of resolve

This commit is contained in:
Mikhail Glukhikh
2020-09-14 19:05:18 +03:00
parent 54d5494ecd
commit 0c13d3197c
4 changed files with 24 additions and 18 deletions
@@ -13,8 +13,8 @@ FILE: withInInitializer.kt
super<R|kotlin/Any|>()
}
public final val list: R|kotlin/collections/List<it(kotlin/Comparable<*> & java/io/Serializable)>| = R|kotlin/collections/listOf|<R|it(kotlin/Comparable<*> & java/io/Serializable)|>(vararg(Int(1), Int(2), Int(3), String()))
public get(): R|kotlin/collections/List<it(kotlin/Comparable<*> & java/io/Serializable)>|
public final val list: R|kotlin/collections/List<kotlin/Any>| = R|kotlin/collections/listOf|<R|it(kotlin/Comparable<*> & java/io/Serializable)|>(vararg(Int(1), Int(2), Int(3), String()))
public get(): R|kotlin/collections/List<kotlin/Any>|
public final val data: R|First| = R|/First.First|(Int(42))
public get(): R|First|
@@ -968,6 +968,19 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
}
}
private fun ConeKotlinType.requiresApproximationInPublicPosition(): Boolean {
return when (this) {
is ConeIntegerLiteralType,
is ConeCapturedType,
is ConeDefinitelyNotNullType,
is ConeIntersectionType -> true
is ConeClassLikeType -> typeArguments.any {
it is ConeKotlinTypeProjection && it.type.requiresApproximationInPublicPosition()
}
else -> false
}
}
private fun FirTypeRef.approximateTypeIfNeeded(
containingCallableVisibility: Visibility?,
isInlineFunction: Boolean = false
@@ -975,20 +988,14 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
val approximatedType = if (this is FirResolvedTypeRef &&
(containingCallableVisibility == Public || containingCallableVisibility == Protected)
) {
when (this.type) {
is ConeIntegerLiteralType,
is ConeCapturedType,
is ConeDefinitelyNotNullType,
is ConeIntersectionType -> {
this.withReplacedConeType(
inferenceComponents.approximator.approximateToSuperType(
this.type, TypeApproximatorConfiguration.PublicDeclaration
) as ConeKotlinType
)
}
else -> {
this
}
if (type.requiresApproximationInPublicPosition()) {
this.withReplacedConeType(
inferenceComponents.approximator.approximateToSuperType(
this.type, TypeApproximatorConfiguration.PublicDeclaration
) as? ConeKotlinType
)
} else {
this
}
} else {
this
@@ -1,4 +1,3 @@
// IGNORE_BACKEND_FIR: JVM_IR
interface In<in E>
class A : In<A>
class B : In<B>
@@ -20,5 +20,5 @@ fun <S> test(i: Int, s: S) {
c
takeInvInt(create(i))
<!INAPPLICABLE_CANDIDATE!>takeInvInt<!>(create(i))
}