diff --git a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt
index e8f83fda9a3..4e99ad83677 100644
--- a/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt
+++ b/idea/src/org/jetbrains/kotlin/idea/intentions/branchedTransformations/IfThenUtils.kt
@@ -289,15 +289,22 @@ internal fun KtIfExpression.buildSelectTransformationData(): IfThenToSelectData?
return IfThenToSelectData(context, condition, receiverExpression, baseClause, negatedClause)
}
+internal fun KtExpression?.isClauseTransformableToLetOnly() =
+ this is KtCallExpression && resolveToCall()?.getImplicitReceiverValue() == null
+
internal fun KtIfExpression.shouldBeTransformed(): Boolean {
val condition = condition
return when (condition) {
- is KtBinaryExpression -> true
+ is KtBinaryExpression -> {
+ val baseClause = (if (condition.operationToken == KtTokens.EQEQ) `else` else then)?.unwrapBlockOrParenthesis()
+ !baseClause.isClauseTransformableToLetOnly()
+ }
is KtIsExpression -> {
- if (!isMultiLine()) true
- else {
- val baseClause = (if (condition.isNegated) `else` else then)?.unwrapBlockOrParenthesis()
- baseClause !is KtDotQualifiedExpression
+ val baseClause = (if (condition.isNegated) `else` else then)?.unwrapBlockOrParenthesis()
+ when {
+ baseClause.isClauseTransformableToLetOnly() -> false
+ !isMultiLine() -> true
+ else -> baseClause !is KtDotQualifiedExpression
}
}
else -> false
diff --git a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call.kt b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call.kt
index ebceb7a3c04..265b51061ac 100644
--- a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call.kt
+++ b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call.kt
@@ -1,4 +1,5 @@
// WITH_RUNTIME
+// HIGHLIGHT: INFORMATION
fun convert(x: String, y: String) = ""
fun foo(a: String?, b: String) {
diff --git a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call.kt.after
index c1eaace88c2..f96c8485d64 100644
--- a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call.kt.after
+++ b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call.kt.after
@@ -1,4 +1,5 @@
// WITH_RUNTIME
+// HIGHLIGHT: INFORMATION
fun convert(x: String, y: String) = ""
fun foo(a: String?, b: String) {
diff --git a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call2.kt b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call2.kt
index 47693ec26c3..fb1eac18306 100644
--- a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call2.kt
+++ b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call2.kt
@@ -1,4 +1,5 @@
// WITH_RUNTIME
+// HIGHLIGHT: INFORMATION
fun convert(x: String, y: String) = ""
fun foo(a: Any?, b: String) {
diff --git a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call2.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call2.kt.after
index 294bea03985..53ea330dd5f 100644
--- a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call2.kt.after
+++ b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call2.kt.after
@@ -1,4 +1,5 @@
// WITH_RUNTIME
+// HIGHLIGHT: INFORMATION
fun convert(x: String, y: String) = ""
fun foo(a: Any?, b: String) {
diff --git a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call3.kt b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call3.kt
index a33521d90a8..69ece72692a 100644
--- a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call3.kt
+++ b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call3.kt
@@ -1,4 +1,5 @@
// WITH_RUNTIME
+// HIGHLIGHT: INFORMATION
fun convert(x: String, y: Int) = ""
fun foo(a: String?, it: Int) {
diff --git a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call3.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call3.kt.after
index 0819e5302a9..2110d53a9b8 100644
--- a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call3.kt.after
+++ b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call3.kt.after
@@ -1,4 +1,5 @@
// WITH_RUNTIME
+// HIGHLIGHT: INFORMATION
fun convert(x: String, y: Int) = ""
fun foo(a: String?, it: Int) {
diff --git a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call4.kt b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call4.kt
index 56779927ef3..56c7aa053a6 100644
--- a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call4.kt
+++ b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call4.kt
@@ -1,4 +1,5 @@
// WITH_RUNTIME
+// HIGHLIGHT: INFORMATION
fun maybeFoo(): String? {
return "foo"
}
diff --git a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call4.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call4.kt.after
index cde5f47fc7f..32de64e8035 100644
--- a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call4.kt.after
+++ b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/call4.kt.after
@@ -1,4 +1,5 @@
// WITH_RUNTIME
+// HIGHLIGHT: INFORMATION
fun maybeFoo(): String? {
return "foo"
}
diff --git a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/inspectionData/expected.xml b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/inspectionData/expected.xml
index c612d3e163b..bec92be1bf0 100644
--- a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/inspectionData/expected.xml
+++ b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/inspectionData/expected.xml
@@ -167,40 +167,4 @@
If-Then foldable to '?.'
Foldable if-then
-
- call4.kt
- 10
- light_idea_test_case
- <default>
-
- If-Then foldable to '?.'
- Foldable if-then
-
-
- call3.kt
- 5
- light_idea_test_case
- <default>
-
- If-Then foldable to '?.'
- Foldable if-then
-
-
- call2.kt
- 5
- light_idea_test_case
- <default>
-
- If-Then foldable to '?.'
- Foldable if-then
-
-
- call.kt
- 5
- light_idea_test_case
- <default>
-
- If-Then foldable to '?.'
- Foldable if-then
-