[NI] Refine nullability for CST of types with undefined nullability
This commit is contained in:
+12
-2
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.checker.*
|
||||
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
|
||||
import org.jetbrains.kotlin.types.typeUtil.canHaveUndefinedNullability
|
||||
|
||||
object NewCommonSuperTypeCalculator {
|
||||
|
||||
@@ -61,9 +62,18 @@ object NewCommonSuperTypeCalculator {
|
||||
val notAllNotNull = types.any { !NullabilityChecker.isSubtypeOfAny(it) }
|
||||
val notNullTypes = if (notAllNotNull) types.map { it.makeNullableAsSpecified(false) } else types
|
||||
|
||||
val commonSuperTypes = commonSuperTypeForNotNullTypes(notNullTypes, depth)
|
||||
val commonSuperType = commonSuperTypeForNotNullTypes(notNullTypes, depth)
|
||||
return if (notAllNotNull)
|
||||
refineNullabilityForUndefinedNullability(types, commonSuperType) ?: commonSuperType.makeNullableAsSpecified(true)
|
||||
else
|
||||
commonSuperType
|
||||
}
|
||||
|
||||
return if (notAllNotNull) commonSuperTypes.makeNullableAsSpecified(true) else commonSuperTypes
|
||||
private fun refineNullabilityForUndefinedNullability(types: List<SimpleType>, commonSuperType: SimpleType): SimpleType? {
|
||||
if (!commonSuperType.unwrap().canHaveUndefinedNullability()) return null
|
||||
|
||||
val actuallyNotNull = types.all { NullabilityChecker.hasPathByNotMarkedNullableNodes(it, commonSuperType.constructor) }
|
||||
return if (actuallyNotNull) commonSuperType else null
|
||||
}
|
||||
|
||||
private fun List<SimpleType>.uniquify(): List<SimpleType> {
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
package
|
||||
|
||||
public fun foobar(/*0*/ a: A, /*1*/ b: B): In<kotlin.Nothing>?
|
||||
public fun </*0*/ T> select(/*0*/ x: T, /*1*/ y: T): T?
|
||||
public fun foobar(/*0*/ a: A, /*1*/ b: B): In<kotlin.Nothing>
|
||||
public fun </*0*/ T> select(/*0*/ x: T, /*1*/ y: T): T
|
||||
|
||||
public final class A : In<A> {
|
||||
public constructor A()
|
||||
|
||||
@@ -12,7 +12,7 @@ fun <T> test(v: T): T {
|
||||
v
|
||||
}
|
||||
|
||||
val t: T = <!NI;DEBUG_INFO_SMARTCAST!>a<!>
|
||||
val t: T = a
|
||||
return t
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ fun <T> test3(v: T): T {
|
||||
v
|
||||
}
|
||||
|
||||
val t: T = <!NI;DEBUG_INFO_SMARTCAST!>a<!>
|
||||
val t: T = a
|
||||
return t
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
// !DIAGNOSTICS: -NOTHING_TO_INLINE
|
||||
// NI_EXPECTED_FILE
|
||||
|
||||
inline fun <T> foo(t1: T, t2: T) = t1 ?: t2
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package
|
||||
|
||||
public inline fun </*0*/ T> bar(/*0*/ l: (T) -> kotlin.Unit): T
|
||||
public inline fun </*0*/ T> foo(/*0*/ t1: T, /*1*/ t2: T): T?
|
||||
public fun use(): kotlin.Unit
|
||||
@@ -1,5 +1,4 @@
|
||||
// !DIAGNOSTICS: -NOTHING_TO_INLINE
|
||||
// NI_EXPECTED_FILE
|
||||
// See KT-9143: smart cast on a variable nulled inside a lambda argument
|
||||
inline fun <T> foo(t1: T, t2: T) = t1 ?: t2
|
||||
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
package
|
||||
|
||||
public inline fun </*0*/ T> bar(/*0*/ l: (T) -> kotlin.Unit): T
|
||||
public inline fun </*0*/ T> foo(/*0*/ t1: T, /*1*/ t2: T): T?
|
||||
public fun use(): kotlin.Unit
|
||||
Reference in New Issue
Block a user