From 7bedb6bca81be21ed17a6454132e76054521b2a3 Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Mon, 4 Oct 2021 15:03:08 +0300 Subject: [PATCH] [FIR] Propagate not-null info into TypeOperatorCall ^KT-44559 Fixed --- .../kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt | 8 ++++++-- .../testData/diagnostics/notLinked/dfa/pos/25.fir.kt | 6 +++--- .../testData/diagnostics/notLinked/dfa/pos/26.fir.kt | 6 +++--- .../testData/diagnostics/notLinked/dfa/pos/27.fir.kt | 6 +++--- .../testData/diagnostics/notLinked/dfa/pos/31.fir.kt | 10 +++++----- .../testData/diagnostics/notLinked/dfa/pos/40.fir.kt | 4 ++-- .../testData/diagnostics/notLinked/dfa/pos/68.fir.kt | 8 ++++---- .../testData/diagnostics/notLinked/dfa/pos/69.fir.kt | 4 ++-- 8 files changed, 28 insertions(+), 24 deletions(-) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt index e438b3d4a15..af8bbd6371f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/dfa/FirDataFlowAnalyzer.kt @@ -669,8 +669,12 @@ abstract class FirDataFlowAnalyzer( } } when (this) { - is FirSafeCallExpression -> this.receiver.propagateNotNullInfo() - is FirTypeOperatorCall -> this.argument.propagateNotNullInfo() + is FirSafeCallExpression -> receiver.propagateNotNullInfo() + is FirTypeOperatorCall -> { + if (operation == FirOperation.AS || operation == FirOperation.SAFE_AS) { + argument.propagateNotNullInfo() + } + } } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/25.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/25.fir.kt index 1b8377b9557..d43aeb5a12a 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/25.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/25.fir.kt @@ -51,9 +51,9 @@ inline fun case_3(x: Any?) { inline fun case_4(x: Any?) { (x as? T)!! if (x is T?) { - x - x.length - x.get(0) + x + x.length + x.get(0) } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/26.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/26.fir.kt index 1b8377b9557..d43aeb5a12a 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/26.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/26.fir.kt @@ -51,9 +51,9 @@ inline fun case_3(x: Any?) { inline fun case_4(x: Any?) { (x as? T)!! if (x is T?) { - x - x.length - x.get(0) + x + x.length + x.get(0) } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/27.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/27.fir.kt index 1b8377b9557..d43aeb5a12a 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/27.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/27.fir.kt @@ -51,9 +51,9 @@ inline fun case_3(x: Any?) { inline fun case_4(x: Any?) { (x as? T)!! if (x is T?) { - x - x.length - x.get(0) + x + x.length + x.get(0) } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/31.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/31.fir.kt index 93ae62955b7..155cb6020fb 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/31.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/31.fir.kt @@ -54,11 +54,11 @@ fun case_3(x: Any?) { */ fun case_4(x: Any?) { if ((x as Class?)!!.prop_8?.prop_8?.prop_8?.prop_8 == null) else { - x - x.prop_8 - x.prop_8.prop_8 - x.prop_8.prop_8.prop_8 - x.prop_8.prop_8.prop_8.prop_8.prop_8 + x + x.prop_8 + x.prop_8.prop_8 + x.prop_8.prop_8.prop_8 + x.prop_8.prop_8.prop_8.prop_8.prop_8 } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/40.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/40.fir.kt index b8a015181a2..11d249deefd 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/40.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/40.fir.kt @@ -97,8 +97,8 @@ fun case_10(x: Any?) { */ fun case_11(x: Any?) { if ((x as Boolean?)!!) { - x.not() - select(x).not() + x.not() + select(x).not() } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/68.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/68.fir.kt index 7e7f0616be1..7b78b7c207f 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/68.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/68.fir.kt @@ -14,8 +14,8 @@ fun case_1(x: Any?) { // TESTCASE NUMBER: 2 fun case_2(x: Any?) { (x as Nothing?)!! - x - x.inv() + x + x.inv() } // TESTCASE NUMBER: 3 @@ -45,8 +45,8 @@ fun case_5(x: Any?) { // TESTCASE NUMBER: 6 fun case_6(x: Any?) { (x as String?)!! - x - x.length + x + x.length } // TESTCASE NUMBER: 7 diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/69.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/69.fir.kt index 9a735e8d67e..d7d879a243a 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/69.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/pos/69.fir.kt @@ -13,8 +13,8 @@ fun test1(x: ClassLevel1?) { // TESTCASE NUMBER: 2 fun case_2(x: Any?) { (x as ClassLevel1?)!! - x - x.test1() + x + x.test1() } // TESTCASE NUMBER: 3