[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:
Pavel Kirpichenkov
2020-03-10 18:23:51 +03:00
parent 88ae9bc7d5
commit 04f9a03796
7 changed files with 56 additions and 0 deletions
@@ -15237,6 +15237,11 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirOldFronte
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")
public void testElvisOnUnit() throws Exception {
runTest("compiler/testData/diagnostics/tests/nullableTypes/elvisOnUnit.kt");
@@ -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
}
}
@@ -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
}
}
@@ -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");
}
@TestMetadata("definitelyNotNullWithNullableBound.kt")
public void testDefinitelyNotNullWithNullableBound() throws Exception {
runTest("compiler/testData/diagnostics/tests/nullableTypes/definitelyNotNullWithNullableBound.kt");
}
@TestMetadata("elvisOnUnit.kt")
public void testElvisOnUnit() throws Exception {
runTest("compiler/testData/diagnostics/tests/nullableTypes/elvisOnUnit.kt");
@@ -15239,6 +15239,11 @@ public class DiagnosticsUsingJavacTestGenerated extends AbstractDiagnosticsUsing
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")
public void testElvisOnUnit() throws Exception {
runTest("compiler/testData/diagnostics/tests/nullableTypes/elvisOnUnit.kt");
@@ -295,6 +295,9 @@ public class TypeUtils {
if (FlexibleTypesKt.isFlexible(type) && isNullableType(FlexibleTypesKt.asFlexibleType(type).getUpperBound())) {
return true;
}
if (SpecialTypesKt.isDefinitelyNotNullType(type)) {
return false;
}
if (isTypeParameter(type)) {
return hasNullableSuperType(type);
}