[NI] Fix isNullableType for definitely not null type parameter
Consider type parameter with nullable bound not null if it is inside of a definitely not null type.
This commit is contained in:
Generated
+5
@@ -15237,6 +15237,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
|
|||||||
runTest("compiler/testData/diagnostics/tests/nullableTypes/baseWithNullableUpperBound.kt");
|
runTest("compiler/testData/diagnostics/tests/nullableTypes/baseWithNullableUpperBound.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("definitelyNotNullWithNullableBound.kt")
|
||||||
|
public void testDefinitelyNotNullWithNullableBound() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/nullableTypes/definitelyNotNullWithNullableBound.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("elvisOnUnit.kt")
|
@TestMetadata("elvisOnUnit.kt")
|
||||||
public void testElvisOnUnit() throws Exception {
|
public void testElvisOnUnit() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/nullableTypes/elvisOnUnit.kt");
|
runTest("compiler/testData/diagnostics/tests/nullableTypes/elvisOnUnit.kt");
|
||||||
|
|||||||
Vendored
+17
@@ -0,0 +1,17 @@
|
|||||||
|
// !LANGUAGE: +NewInference
|
||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_EXPRESSION
|
||||||
|
|
||||||
|
fun <D> makeDefinitelyNotNull(arg: D?): D = TODO()
|
||||||
|
|
||||||
|
fun <N : Number?> test(arg: N) {
|
||||||
|
makeDefinitelyNotNull(arg) ?: 1
|
||||||
|
|
||||||
|
makeDefinitelyNotNull(arg)!!
|
||||||
|
|
||||||
|
makeDefinitelyNotNull(arg)?.toInt()
|
||||||
|
|
||||||
|
val nullImposible = when (val dnn = makeDefinitelyNotNull(arg)) {
|
||||||
|
null -> false
|
||||||
|
else -> true
|
||||||
|
}
|
||||||
|
}
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
// !LANGUAGE: +NewInference
|
||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_EXPRESSION
|
||||||
|
|
||||||
|
fun <D> makeDefinitelyNotNull(arg: D?): D = TODO()
|
||||||
|
|
||||||
|
fun <N : Number?> test(arg: N) {
|
||||||
|
makeDefinitelyNotNull(arg) <!USELESS_ELVIS!>?: 1<!>
|
||||||
|
|
||||||
|
makeDefinitelyNotNull(arg)<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>
|
||||||
|
|
||||||
|
makeDefinitelyNotNull(arg)<!UNNECESSARY_SAFE_CALL!>?.<!>toInt()
|
||||||
|
|
||||||
|
val nullImposible = when (val dnn = makeDefinitelyNotNull(arg)) {
|
||||||
|
<!SENSELESS_NULL_IN_WHEN!>null<!> -> false
|
||||||
|
else -> true
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
@@ -0,0 +1,4 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun </*0*/ D> makeDefinitelyNotNull(/*0*/ arg: D?): D
|
||||||
|
public fun </*0*/ N : kotlin.Number?> test(/*0*/ arg: N): kotlin.Unit
|
||||||
@@ -15244,6 +15244,11 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTestWithFirVali
|
|||||||
runTest("compiler/testData/diagnostics/tests/nullableTypes/baseWithNullableUpperBound.kt");
|
runTest("compiler/testData/diagnostics/tests/nullableTypes/baseWithNullableUpperBound.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("definitelyNotNullWithNullableBound.kt")
|
||||||
|
public void testDefinitelyNotNullWithNullableBound() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/nullableTypes/definitelyNotNullWithNullableBound.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("elvisOnUnit.kt")
|
@TestMetadata("elvisOnUnit.kt")
|
||||||
public void testElvisOnUnit() throws Exception {
|
public void testElvisOnUnit() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/nullableTypes/elvisOnUnit.kt");
|
runTest("compiler/testData/diagnostics/tests/nullableTypes/elvisOnUnit.kt");
|
||||||
|
|||||||
Generated
+5
@@ -15239,6 +15239,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
|
|||||||
runTest("compiler/testData/diagnostics/tests/nullableTypes/baseWithNullableUpperBound.kt");
|
runTest("compiler/testData/diagnostics/tests/nullableTypes/baseWithNullableUpperBound.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("definitelyNotNullWithNullableBound.kt")
|
||||||
|
public void testDefinitelyNotNullWithNullableBound() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/tests/nullableTypes/definitelyNotNullWithNullableBound.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("elvisOnUnit.kt")
|
@TestMetadata("elvisOnUnit.kt")
|
||||||
public void testElvisOnUnit() throws Exception {
|
public void testElvisOnUnit() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/tests/nullableTypes/elvisOnUnit.kt");
|
runTest("compiler/testData/diagnostics/tests/nullableTypes/elvisOnUnit.kt");
|
||||||
|
|||||||
@@ -295,6 +295,9 @@ public class TypeUtils {
|
|||||||
if (FlexibleTypesKt.isFlexible(type) && isNullableType(FlexibleTypesKt.asFlexibleType(type).getUpperBound())) {
|
if (FlexibleTypesKt.isFlexible(type) && isNullableType(FlexibleTypesKt.asFlexibleType(type).getUpperBound())) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (SpecialTypesKt.isDefinitelyNotNullType(type)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (isTypeParameter(type)) {
|
if (isTypeParameter(type)) {
|
||||||
return hasNullableSuperType(type);
|
return hasNullableSuperType(type);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user