[FIR] Fold flexible types after substitution if possible

This commit is contained in:
Mikhail Glukhikh
2020-10-15 11:48:52 +03:00
parent acb03cb28c
commit abc2866902
3 changed files with 8 additions and 3 deletions
@@ -8,7 +8,7 @@ FILE: main.kt
^ R|<local>/x|.R|kotlin/Any.toString|()
}
)
R|/MyFunction|<R|kotlin/Nothing|, R|kotlin/Any?|>(<L> = MyFunction@fun <anonymous>(x: R|ft<kotlin/Nothing, kotlin/Nothing?>!|): R|ft<kotlin/Any?, kotlin/Any?>?| {
R|/MyFunction|<R|kotlin/Nothing|, R|kotlin/Any?|>(<L> = MyFunction@fun <anonymous>(x: R|ft<kotlin/Nothing, kotlin/Nothing?>!|): R|kotlin/Any?| {
^ String()
}
)
@@ -50,7 +50,12 @@ abstract class AbstractConeSubstitutor : ConeSubstitutor() {
is ConeClassErrorType -> return null
is ConeClassLikeType -> this.substituteArguments()
is ConeLookupTagBasedType -> return null
is ConeFlexibleType -> this.substituteBounds()
is ConeFlexibleType -> this.substituteBounds()?.let {
// TODO: may be (?) it's worth adding regular type comparison via AbstractTypeChecker
// However, the simplified check here should be enough for typical flexible types
if (it.lowerBound == it.upperBound) it.lowerBound
else it
}
is ConeCapturedType -> return null
is ConeDefinitelyNotNullType -> this.substituteOriginal()
is ConeIntersectionType -> this.substituteIntersectedTypes()
@@ -53,7 +53,7 @@ public class JavaClassCase3{
// TESTCASE NUMBER: 3
fun case3() {
val x = JavaClassCase3.id(null) // Nothing!
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing?..kotlin.Nothing??")!>x<!>
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing?")!>x<!>
val a = if (x) {
"NOK"
} else "NOK"