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 12876b6fc9a..9208c511dc1 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 @@ -446,22 +446,27 @@ abstract class FirDataFlowAnalyzer( if (operandVariable.isReal()) { flow.addTypeStatement(operandVariable typeEq type) } - logicSystem.approveStatementsInsideFlow( - flow, - operandVariable notEq null, - shouldRemoveSynthetics = true, - shouldForkFlow = false - ) + if (!type.canBeNull) { + logicSystem.approveStatementsInsideFlow( + flow, + operandVariable notEq null, + shouldRemoveSynthetics = true, + shouldForkFlow = false + ) + } else { + val expressionVariable = variableStorage.createSyntheticVariable(typeOperatorCall) + flow.addImplication((expressionVariable notEq null) implies (operandVariable notEq null)) + } } FirOperation.SAFE_AS -> { val expressionVariable = variableStorage.createSyntheticVariable(typeOperatorCall) + flow.addImplication((expressionVariable notEq null) implies (operandVariable notEq null)) if (operandVariable.isReal()) { flow.addImplication((expressionVariable notEq null) implies (operandVariable typeEq type)) - flow.addImplication((expressionVariable eq null) implies (operandVariable typeNotEq type)) - } - if (type.nullability == ConeNullability.NOT_NULL) { - flow.addImplication((expressionVariable notEq null) implies (operandVariable notEq null)) + if (!type.canBeNull) { + flow.addImplication((expressionVariable eq null) implies (operandVariable typeNotEq type)) + } } } 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 789478901af..5810e18b74d 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 @@ -38,11 +38,11 @@ fun case_2(x: Class?) { */ fun case_3(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 } } @@ -87,7 +87,7 @@ fun case_6(x: Class?) { 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.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 e3013f90025..43411254616 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 @@ -120,8 +120,8 @@ fun case_12(x: Any?) { */ fun case_13(x: Any?) { if (x as Boolean? ?: x!!) { - 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 5369c43c34b..050d1cbaad3 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 @@ -20,24 +20,24 @@ fun case_2(x: Any?) { // TESTCASE NUMBER: 3 fun case_3(x: Any?) { if (x as Number? is Int) { - x - x.inv() + x + x.inv() } } // TESTCASE NUMBER: 4 fun case_4(x: Any?) { if (x as Class? is Class) { - x - x.prop_1 + x + x.prop_1 } } // TESTCASE NUMBER: 5 fun case_5(x: Any?) { if (x as Nothing? is Nothing) { - x - x.inv() + x + x.inv() } } @@ -51,8 +51,8 @@ fun case_6(x: Any?) { // TESTCASE NUMBER: 7 fun case_7(x: Any?) { if (x as String? != null) { - x - x.length + x + x.length } } 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 2b458be5fa9..fccc3073011 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 @@ -19,8 +19,8 @@ fun case_2(x: Any?) { // TESTCASE NUMBER: 3 fun case_3(x: Any?) { if (x as ClassLevel1? is ClassLevel1) { - x - x.test1() + x + x.test1() } }