FIR: more accurate nullability of intersection of flexible types

This commit is contained in:
Jinseong Jeon
2021-04-01 22:58:58 -07:00
committed by Dmitriy Novozhilov
parent 871b5a2174
commit 0d3969597c
4 changed files with 21 additions and 6 deletions
@@ -145,11 +145,7 @@ 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
this is ConeFlexibleType -> upperBound.resultNullability(context)
ConeNullabilityChecker.isSubtypeOfAny(context, this) -> NOT_NULL
else -> UNKNOWN
}
@@ -1,7 +1,12 @@
// FILE: J.java
import org.jetbrains.annotations.*;
import java.util.List;
class J {
static String foo() { return "abc"; }
@NotNull
static List<String> bar() { return new List<String>(); }
}
// FILE: test.kt
@@ -11,6 +16,10 @@ fun bar() {
v = J.foo()
v<!UNSAFE_CALL!>.<!>length
<!INAPPLICABLE_CANDIDATE!>gav<!>(v)
var l: List<String>?
l = J.bar()
l.isEmpty()
}
fun gav(v: String) = v
@@ -1,7 +1,12 @@
// FILE: J.java
import org.jetbrains.annotations.*;
import java.util.List;
class J {
static String foo() { return "abc"; }
@NotNull
static List<String> bar() { return new List<String>(); }
}
// FILE: test.kt
@@ -11,6 +16,10 @@ fun bar() {
v = J.foo()
<!DEBUG_INFO_SMARTCAST!>v<!>.length
gav(<!DEBUG_INFO_SMARTCAST!>v<!>)
var l: List<String>?
l = J.bar()
<!DEBUG_INFO_SMARTCAST!>l<!>.isEmpty()
}
fun gav(v: String) = v
fun gav(v: String) = v
@@ -10,5 +10,6 @@ public/*package*/ open class J {
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
// Static members
@org.jetbrains.annotations.NotNull public/*package*/ open fun bar(): kotlin.collections.(Mutable)List<kotlin.String!>
public/*package*/ open fun foo(): kotlin.String!
}