FIR: fix nullability computation of intersection of flexible types
Without this, currently, it(ft(J..J?), ft(J..J?) => J which should be ft(J..J?) instead.
This commit is contained in:
committed by
Dmitriy Novozhilov
parent
0cb039eea7
commit
871b5a2174
@@ -145,8 +145,13 @@ object ConeTypeIntersector {
|
||||
protected fun ConeKotlinType.resultNullability(context: ConeTypeContext): ResultNullability =
|
||||
when {
|
||||
isMarkedNullable -> ACCEPT_NULL
|
||||
// Technically, upper bound's nullability is more accurate, e.g., a type from Java with @NotNull.
|
||||
// However, it requires one more recursive call here. In contrast, UNKNOWN here is a safe approximation: for even such
|
||||
// flexible type case, as long as the upper bound is still used in the intersection computation (and it indeed is),
|
||||
// we will still get the same nullability from the resulting intersected type.
|
||||
this is ConeFlexibleType -> UNKNOWN
|
||||
ConeNullabilityChecker.isSubtypeOfAny(context, this) -> NOT_NULL
|
||||
else -> UNKNOWN
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+3
-3
@@ -23,7 +23,7 @@ fun g(x: B<Int>) {
|
||||
}
|
||||
|
||||
if (y is Nothing?) {
|
||||
<!OVERLOAD_RESOLUTION_AMBIGUITY!>f<!>(y)
|
||||
<!OVERLOAD_RESOLUTION_AMBIGUITY!>g<!>(y)
|
||||
f(y)
|
||||
<!NONE_APPLICABLE!>g<!>(y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -9,8 +9,8 @@ class J {
|
||||
fun bar() {
|
||||
var v: String?
|
||||
v = J.foo()
|
||||
v.length
|
||||
gav(v)
|
||||
v<!UNSAFE_CALL!>.<!>length
|
||||
<!INAPPLICABLE_CANDIDATE!>gav<!>(v)
|
||||
}
|
||||
|
||||
fun gav(v: String) = v
|
||||
fun gav(v: String) = v
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ fun case2() {
|
||||
fun case3() {
|
||||
val a1 = false
|
||||
val a2 = JavaClass.VALUE
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any..kotlin.Any?! & kotlin.Any")!>a2<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any..kotlin.Any?!")!>a2<!>
|
||||
|
||||
val x3 = a1 && a2
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Boolean")!>x3<!>
|
||||
|
||||
+1
-1
@@ -41,7 +41,7 @@ fun case2() {
|
||||
fun case3() {
|
||||
val a1 = false
|
||||
val a2 = JavaClass.VALUE
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any..kotlin.Any?! & kotlin.Any")!>a2<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any..kotlin.Any?!")!>a2<!>
|
||||
|
||||
val x3 = a1 || a2
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Boolean")!>x3<!>
|
||||
|
||||
+2
-2
@@ -22,7 +22,7 @@ import checkSubtype
|
||||
// TESTCASE NUMBER: 1
|
||||
fun case1() {
|
||||
val a = JavaClass.STR
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String..kotlin.String?! & kotlin.String")!>a<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String..kotlin.String?!")!>a<!>
|
||||
val res = a!!
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.String")!>res<!>
|
||||
}
|
||||
@@ -30,7 +30,7 @@ fun case1() {
|
||||
// TESTCASE NUMBER: 2
|
||||
fun case2() {
|
||||
val a = JavaClass.obj
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any..kotlin.Any?! & kotlin.Any")!>a<!>
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any..kotlin.Any?!")!>a<!>
|
||||
val x = a!!
|
||||
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Any")!>x<!>
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user