[NI] Fix not-null smartcast on intersection of nullable types
#KT-28670 Fixed
This commit is contained in:
+1
-1
@@ -142,7 +142,7 @@ internal class DataFlowInfoImpl private constructor(
|
|||||||
|
|
||||||
private fun KotlinType.canBeDefinitelyNotNullOrNotNull(settings: LanguageVersionSettings): Boolean {
|
private fun KotlinType.canBeDefinitelyNotNullOrNotNull(settings: LanguageVersionSettings): Boolean {
|
||||||
return if (settings.supportsFeature(LanguageFeature.NewInference))
|
return if (settings.supportsFeature(LanguageFeature.NewInference))
|
||||||
this.isMarkedNullable || DefinitelyNotNullType.makesSenseToBeDefinitelyNotNull(this.unwrap())
|
TypeUtils.isNullableType(this)
|
||||||
else
|
else
|
||||||
this.isMarkedNullable
|
this.isMarkedNullable
|
||||||
}
|
}
|
||||||
|
|||||||
+18
@@ -0,0 +1,18 @@
|
|||||||
|
// !LANGUAGE: +NewInference
|
||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
|
||||||
|
interface A
|
||||||
|
interface B {
|
||||||
|
fun test() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <K> select(a: K, b: K): K = a
|
||||||
|
|
||||||
|
fun test(a: A?, b: B?) {
|
||||||
|
b as A?
|
||||||
|
a as B?
|
||||||
|
val c = select(a, b)
|
||||||
|
if (c != null) {
|
||||||
|
<!DEBUG_INFO_SMARTCAST!>c<!>.test()
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun </*0*/ K> select(/*0*/ a: K, /*1*/ b: K): K
|
||||||
|
public fun test(/*0*/ a: A?, /*1*/ b: B?): kotlin.Unit
|
||||||
|
|
||||||
|
public interface A {
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface B {
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open fun test(): kotlin.Unit
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
@@ -8435,6 +8435,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
|||||||
runTest("compiler/testData/diagnostics/tests/generics/nullability/kt25182.kt");
|
runTest("compiler/testData/diagnostics/tests/generics/nullability/kt25182.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("notNullSmartcastOnIntersectionOfNullables.kt")
|
||||||
|
public void testNotNullSmartcastOnIntersectionOfNullables() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/generics/nullability/notNullSmartcastOnIntersectionOfNullables.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nullToGeneric.kt")
|
@TestMetadata("nullToGeneric.kt")
|
||||||
public void testNullToGeneric() throws Exception {
|
public void testNullToGeneric() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/generics/nullability/nullToGeneric.kt");
|
runTest("compiler/testData/diagnostics/tests/generics/nullability/nullToGeneric.kt");
|
||||||
|
|||||||
Generated
+5
@@ -8435,6 +8435,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
|||||||
runTest("compiler/testData/diagnostics/tests/generics/nullability/kt25182.kt");
|
runTest("compiler/testData/diagnostics/tests/generics/nullability/kt25182.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("notNullSmartcastOnIntersectionOfNullables.kt")
|
||||||
|
public void testNotNullSmartcastOnIntersectionOfNullables() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/generics/nullability/notNullSmartcastOnIntersectionOfNullables.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nullToGeneric.kt")
|
@TestMetadata("nullToGeneric.kt")
|
||||||
public void testNullToGeneric() throws Exception {
|
public void testNullToGeneric() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/generics/nullability/nullToGeneric.kt");
|
runTest("compiler/testData/diagnostics/tests/generics/nullability/nullToGeneric.kt");
|
||||||
|
|||||||
@@ -81,8 +81,8 @@ class DefinitelyNotNullType private constructor(val original: SimpleType) : Dele
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun makesSenseToBeDefinitelyNotNull(type: UnwrappedType): Boolean =
|
private fun makesSenseToBeDefinitelyNotNull(type: UnwrappedType): Boolean =
|
||||||
type.canHaveUndefinedNullability() && !NullabilityChecker.isSubtypeOfAny(type)
|
type.canHaveUndefinedNullability() && !NullabilityChecker.isSubtypeOfAny(type)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val delegate: SimpleType
|
override val delegate: SimpleType
|
||||||
|
|||||||
Reference in New Issue
Block a user