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 89e741b9de2..349cbe78531 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 @@ -268,8 +268,15 @@ abstract class FirDataFlowAnalyzer( expressionVariable, shouldRemoveOriginalStatements = operandVariable.isSynthetic() ) { - if (shouldInvert) (it.condition.invert()) implies (it.effect) - else it + when (it.condition.operation) { + Operation.EqNull, Operation.NotEqNull -> { + (expressionVariable eq isEq) implies (it.effect) + } + Operation.EqTrue, Operation.EqFalse -> { + if (shouldInvert) (it.condition.invert()) implies (it.effect) + else it + } + } } } } diff --git a/compiler/fir/resolve/testData/resolve/expresssions/genericDescriptor.kt b/compiler/fir/resolve/testData/resolve/expresssions/genericDescriptor.kt index 764d16a0cd9..1c089007e2b 100644 --- a/compiler/fir/resolve/testData/resolve/expresssions/genericDescriptor.kt +++ b/compiler/fir/resolve/testData/resolve/expresssions/genericDescriptor.kt @@ -32,7 +32,7 @@ fun test(call: Call, resolvedCall: ResolvedCall) { val resolvedDescriptor = resolvedCall.candidateDescriptor if (resolvedDescriptor?.correct() != true) return - resolvedDescriptor.foo() + resolvedDescriptor.foo() } fun otherTest(call: Call<*>, resolvedCall: ResolvedCall<*>) { diff --git a/compiler/fir/resolve/testData/resolve/expresssions/genericDescriptor.txt b/compiler/fir/resolve/testData/resolve/expresssions/genericDescriptor.txt index b167bec8965..c7646d1e673 100644 --- a/compiler/fir/resolve/testData/resolve/expresssions/genericDescriptor.txt +++ b/compiler/fir/resolve/testData/resolve/expresssions/genericDescriptor.txt @@ -21,7 +21,7 @@ FILE: test.kt } } - R|/resolvedDescriptor|.#() + R|/resolvedDescriptor|.R|/foo|() } public final fun otherTest(call: R|Call<*>|, resolvedCall: R|ResolvedCall<*>|): R|kotlin/Unit| { R|/call|.R|FakeOverride|.R|/name| diff --git a/compiler/fir/resolve/testData/resolve/stdlib/problems/complexSmartCasts.kt b/compiler/fir/resolve/testData/resolve/stdlib/problems/complexSmartCasts.kt index 165543e7a17..769a21a8b29 100644 --- a/compiler/fir/resolve/testData/resolve/stdlib/problems/complexSmartCasts.kt +++ b/compiler/fir/resolve/testData/resolve/stdlib/problems/complexSmartCasts.kt @@ -12,10 +12,36 @@ fun foo(a: Any?) { fun bar(s: String?) { if (s?.isNotEmpty() == true) { + s.length + } else { s.length } } +fun bar_2(s: String?) { + if (s?.isNotEmpty() == false) { + s.length + } else { + s.length + } +} + +fun bar_3(s: String?) { + if (s?.isNotEmpty() != true) { + s.length + } else { + s.length + } +} + +fun bar_4(s: String?) { + if (s?.isNotEmpty() != false) { + s.length + } else { + s.length + } +} + fun baz(s: String?) { when { !s.isNullOrEmpty() -> s.length diff --git a/compiler/fir/resolve/testData/resolve/stdlib/problems/complexSmartCasts.txt b/compiler/fir/resolve/testData/resolve/stdlib/problems/complexSmartCasts.txt index 23843c1fb42..993376163fd 100644 --- a/compiler/fir/resolve/testData/resolve/stdlib/problems/complexSmartCasts.txt +++ b/compiler/fir/resolve/testData/resolve/stdlib/problems/complexSmartCasts.txt @@ -25,10 +25,46 @@ FILE: complexSmartCasts.kt public final fun bar(s: R|kotlin/String?|): R|kotlin/Unit| { when () { ==(R|/s|?.R|kotlin/text/isNotEmpty|(), Boolean(true)) -> { + R|/s|.R|kotlin/String.length| + } + else -> { R|/s|.# } } + } + public final fun bar_2(s: R|kotlin/String?|): R|kotlin/Unit| { + when () { + ==(R|/s|?.R|kotlin/text/isNotEmpty|(), Boolean(false)) -> { + R|/s|.R|kotlin/String.length| + } + else -> { + R|/s|.# + } + } + + } + public final fun bar_3(s: R|kotlin/String?|): R|kotlin/Unit| { + when () { + !=(R|/s|?.R|kotlin/text/isNotEmpty|(), Boolean(true)) -> { + R|/s|.# + } + else -> { + R|/s|.R|kotlin/String.length| + } + } + + } + public final fun bar_4(s: R|kotlin/String?|): R|kotlin/Unit| { + when () { + !=(R|/s|?.R|kotlin/text/isNotEmpty|(), Boolean(false)) -> { + R|/s|.# + } + else -> { + R|/s|.R|kotlin/String.length| + } + } + } public final fun baz(s: R|kotlin/String?|): R|kotlin/Unit| { when () {