[NI] Consider type non-nullable only if it has non-null supertype
Fixes #KT-12684 for NI
This commit is contained in:
+8
-1
@@ -250,7 +250,14 @@ internal class DataFlowInfoImpl private constructor(
|
||||
if (!value.type.isFlexible() && value.type.isSubtypeOf(type)) return this
|
||||
|
||||
val nullabilityInfo = hashMapOf<DataFlowValue, Nullability>()
|
||||
if (!type.isMarkedNullable) {
|
||||
|
||||
val isTypeNotNull =
|
||||
if (languageVersionSettings.supportsFeature(LanguageFeature.NewInference))
|
||||
!TypeUtils.isNullableType(type)
|
||||
else
|
||||
!type.isMarkedNullable
|
||||
|
||||
if (isTypeNotNull) {
|
||||
putNullabilityAndTypeInfo(nullabilityInfo, value, NOT_NULL, languageVersionSettings)
|
||||
}
|
||||
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
// !LANGUAGE: +NewInference
|
||||
|
||||
inline fun <T, reified S> foo(x: T?, y: T): T {
|
||||
if (x is S) return <!TYPE_MISMATCH, TYPE_MISMATCH!>x<!>
|
||||
return y
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
public inline fun </*0*/ T, /*1*/ reified S> foo(/*0*/ x: T?, /*1*/ y: T): T
|
||||
@@ -8385,6 +8385,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/nullability/capturedTypeWithPlatformSupertype.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("considerTypeNotNullOnlyIfItHasNotNullBound.kt")
|
||||
public void testConsiderTypeNotNullOnlyIfItHasNotNullBound() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/nullability/considerTypeNotNullOnlyIfItHasNotNullBound.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("correctSubstitutionForIncorporationConstraint.kt")
|
||||
public void testCorrectSubstitutionForIncorporationConstraint() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/nullability/correctSubstitutionForIncorporationConstraint.kt");
|
||||
|
||||
Generated
+5
@@ -8385,6 +8385,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
||||
runTest("compiler/testData/diagnostics/tests/generics/nullability/capturedTypeWithPlatformSupertype.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("considerTypeNotNullOnlyIfItHasNotNullBound.kt")
|
||||
public void testConsiderTypeNotNullOnlyIfItHasNotNullBound() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/nullability/considerTypeNotNullOnlyIfItHasNotNullBound.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("correctSubstitutionForIncorporationConstraint.kt")
|
||||
public void testCorrectSubstitutionForIncorporationConstraint() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/tests/generics/nullability/correctSubstitutionForIncorporationConstraint.kt");
|
||||
|
||||
Reference in New Issue
Block a user