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 7cfc073edd8..4315a9e0eb1 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 @@ -678,30 +678,14 @@ abstract class FirDataFlowAnalyzer( val (node, unionNode) = graphBuilder.exitCheckNotNullCall(checkNotNullCall, callCompleted) node.mergeIncomingFlow() - checkNotNullCall.argument.propagateNotNullInfo(node) + val argumentVariable = variableStorage.getOrCreateVariable(node.previousFlow, checkNotNullCall.argument) + node.flow.assumeNotNull(argumentVariable, shouldForkFlow = false, shouldRemoveSynthetics = false) unionNode?.let { unionFlowFromArguments(it) } } - private fun FirExpression.propagateNotNullInfo(node: CFGNode<*>) { - val symbol = this.symbol - if (symbol != null) { - variableStorage.getOrCreateRealVariable(node.previousFlow, symbol, this)?.let { operandVariable -> - node.flow.assumeNotNull(operandVariable, shouldForkFlow = false, shouldRemoveSynthetics = true) - } - } - when (this) { - is FirSafeCallExpression -> receiver.propagateNotNullInfo(node) - is FirTypeOperatorCall -> { - if (operation == FirOperation.AS || operation == FirOperation.SAFE_AS) { - argument.propagateNotNullInfo(node) - } - } - } - } - private fun FLOW.assumeNotNull(variable: DataFlowVariable, shouldForkFlow: Boolean, shouldRemoveSynthetics: Boolean): FLOW = - logicSystem.approveStatementsInsideFlow(this, variable notEq null, shouldForkFlow, shouldRemoveSynthetics,).also { + logicSystem.approveStatementsInsideFlow(this, variable notEq null, shouldForkFlow, shouldRemoveSynthetics).also { if (variable is RealVariable) { it.addTypeStatement(variable typeEq any andTypeNotEq nullableNothing) } @@ -1380,7 +1364,8 @@ abstract class FirDataFlowAnalyzer( node.mergeIncomingFlow() mergePostponedLambdaExitsNode?.mergeIncomingFlow() if (isLhsNotNull) { - elvisExpression.lhs.propagateNotNullInfo(node) + val lhsVariable = variableStorage.getOrCreateVariable(node.previousFlow, elvisExpression.lhs) + node.flow.assumeNotNull(lhsVariable, shouldForkFlow = false, shouldRemoveSynthetics = true) } if (!components.session.languageVersionSettings.supportsFeature(LanguageFeature.BooleanElvisBoundSmartCasts)) return @@ -1396,7 +1381,7 @@ abstract class FirDataFlowAnalyzer( val lhsVariable = variableStorage.getOrCreateVariable(flow, lhs) val value = rhs.value as Boolean - flow.addImplication(elvisVariable.eq(!value) implies (lhsVariable.notEq(null))) + flow.addImplication((elvisVariable eq !value) implies (lhsVariable notEq null)) } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/14.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/14.fir.kt index 6f0deb9d073..c40e4eae670 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/14.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/analysis/smartcasts/pos/14.fir.kt @@ -63,7 +63,7 @@ fun case_2(value_1: Int?) { // TESTCASE NUMBER: 3 fun case_3(value_1: Int?) { if (contracts.case_3(value_1)!!) { - value_1.inv() + value_1.inv() } } 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 e1da0763c17..2aae13e99de 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 @@ -49,7 +49,7 @@ inline fun case_3(x: Any?) { // TESTCASE NUMBER: 4 inline fun case_4(x: Any?) { (x as? T)!! - if (x is T?) { + if (x is T?) { 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 e1da0763c17..2aae13e99de 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 @@ -49,7 +49,7 @@ inline fun case_3(x: Any?) { // TESTCASE NUMBER: 4 inline fun case_4(x: Any?) { (x as? T)!! - if (x is T?) { + if (x is T?) { 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 e1da0763c17..2aae13e99de 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 @@ -49,7 +49,7 @@ inline fun case_3(x: Any?) { // TESTCASE NUMBER: 4 inline fun case_4(x: Any?) { (x as? T)!! - if (x is T?) { + if (x is T?) { x x.length x.get(0)