diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.java index e642cbddfb2..fd494689cbe 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DelegatingDataFlowInfo.java @@ -219,11 +219,11 @@ import static org.jetbrains.kotlin.resolve.calls.smartcasts.Nullability.NOT_NULL newTypeInfo.putAll(a, collectTypesFromMeAndParents(b)); newTypeInfo.putAll(b, collectTypesFromMeAndParents(a)); if (!a.getType().equals(b.getType())) { - // To avoid smart casts to Nothing or Nothing? and recording base types of own type - if (!KotlinBuiltIns.isNothingOrNullableNothing(b.getType()) && !TypeUtilsKt.isSubtypeOf(a.getType(), b.getType())) { + // To avoid recording base types of own type + if (!TypeUtilsKt.isSubtypeOf(a.getType(), b.getType())) { newTypeInfo.put(a, b.getType()); } - if (!KotlinBuiltIns.isNothingOrNullableNothing(a.getType()) && !TypeUtilsKt.isSubtypeOf(b.getType(), a.getType())) { + if (!TypeUtilsKt.isSubtypeOf(b.getType(), a.getType())) { newTypeInfo.put(b, a.getType()); } } diff --git a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.kt b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.kt index 3cd4605a65c..6dd93c9633a 100644 --- a/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.kt +++ b/compiler/testData/diagnostics/tests/dataFlowInfoTraversal/ExclExcl.kt @@ -3,19 +3,19 @@ fun bar(x: Int) = x + 1 fun f1(x: Int?) { bar(x) if (x != null) bar(x!!) - if (x == null) bar(x!!) + if (x == null) bar(x!!) } fun f2(x: Int?) { - if (x != null) else bar(x!!) + if (x != null) else x!! } fun f3(x: Int?) { - if (x != null) bar(x!!) else bar(x!!) + if (x != null) bar(x!!) else x!! } fun f4(x: Int?) { - if (x == null) bar(x!!) else bar(x!!) + if (x == null) x!! else bar(x!!) } fun f5(x: Int?) { diff --git a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2164.kt b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2164.kt index c1aee6cd6f5..7e5dba858fd 100644 --- a/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2164.kt +++ b/compiler/testData/diagnostics/tests/nullabilityAndSmartCasts/kt2164.kt @@ -22,8 +22,8 @@ fun main(args : Array) { foo(x) } else { foo(x) - foo(x!!) - foo(x) + foo(x!!) + foo(x) } foo(x) diff --git a/compiler/testData/diagnostics/tests/nullableTypes/nullAssertOnTypeWithNullableUpperBound.kt b/compiler/testData/diagnostics/tests/nullableTypes/nullAssertOnTypeWithNullableUpperBound.kt index 2b51253a6c2..63e01551ff4 100644 --- a/compiler/testData/diagnostics/tests/nullableTypes/nullAssertOnTypeWithNullableUpperBound.kt +++ b/compiler/testData/diagnostics/tests/nullableTypes/nullAssertOnTypeWithNullableUpperBound.kt @@ -2,13 +2,13 @@ fun test(t: T): T { if (t != null) { return t!! } - return t!! + return t!! } fun T.testThis(): String { if (this != null) { return this!!.toString() } - return this!!.toString() + return this!!.toString() } diff --git a/compiler/testData/diagnostics/tests/smartCasts/notNullorNotNull.kt b/compiler/testData/diagnostics/tests/smartCasts/notNullorNotNull.kt new file mode 100644 index 00000000000..9dac31ac47e --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/notNullorNotNull.kt @@ -0,0 +1,6 @@ +fun bar(x: Int?): Int { + if (x != null) return -1 + if (x == null) return -2 + // Should be unreachable + return 2 + 2 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/smartCasts/notNullorNotNull.txt b/compiler/testData/diagnostics/tests/smartCasts/notNullorNotNull.txt new file mode 100644 index 00000000000..23b3a20fb4c --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/notNullorNotNull.txt @@ -0,0 +1,3 @@ +package + +public fun bar(/*0*/ x: kotlin.Int?): kotlin.Int diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java index 4fa390f3754..2d8337d718a 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestGenerated.java @@ -14625,6 +14625,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest { doTest(fileName); } + @TestMetadata("notNullorNotNull.kt") + public void testNotNullorNotNull() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/notNullorNotNull.kt"); + doTest(fileName); + } + @TestMetadata("ownerDeclaresBothModifies.kt") public void testOwnerDeclaresBothModifies() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/smartCasts/ownerDeclaresBothModifies.kt");