diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/branchedTransformations/IfThenToSafeAccessInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/branchedTransformations/IfThenToSafeAccessInspection.kt
index 05f118e5434..6ea1b614163 100644
--- a/idea/src/org/jetbrains/kotlin/idea/inspections/branchedTransformations/IfThenToSafeAccessInspection.kt
+++ b/idea/src/org/jetbrains/kotlin/idea/inspections/branchedTransformations/IfThenToSafeAccessInspection.kt
@@ -9,6 +9,7 @@ import com.intellij.codeInspection.ProblemHighlightType
import com.intellij.openapi.editor.Editor
import com.intellij.openapi.project.Project
import com.intellij.psi.PsiDocumentManager
+import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.idea.KotlinBundle
import org.jetbrains.kotlin.idea.core.replaced
import org.jetbrains.kotlin.idea.imports.importableFqName
@@ -100,6 +101,8 @@ private fun IfThenToSelectData.clausesReplaceableBySafeCall(): Boolean = when {
baseClause == null -> false
negatedClause == null && baseClause.isUsedAsExpression(context) -> false
negatedClause != null && !negatedClause.isNullExpression() -> false
+ context.diagnostics.forElement(condition)
+ .any { it.factory == Errors.SENSELESS_COMPARISON || it.factory == Errors.USELESS_IS_CHECK } -> false
baseClause.evaluatesTo(receiverExpression) -> true
baseClause.hasFirstReceiverOf(receiverExpression) -> withoutResultInCallChain(baseClause, context)
baseClause.anyArgumentEvaluatesTo(receiverExpression) -> true
diff --git a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/implicitReceiver3.kt b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/implicitReceiver3.kt
index 593800507fe..4e95a33d908 100644
--- a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/implicitReceiver3.kt
+++ b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/implicitReceiver3.kt
@@ -1,3 +1,4 @@
+// PROBLEM: none
class Foo
class Bar {
diff --git a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/implicitReceiver3.kt.after b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/implicitReceiver3.kt.after
deleted file mode 100644
index 848c9a9a10d..00000000000
--- a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/implicitReceiver3.kt.after
+++ /dev/null
@@ -1,8 +0,0 @@
-class Foo
-
-class Bar {
- fun Foo?.test() {
- this@Bar?.bar()
- }
- fun bar() {}
-}
\ No newline at end of file
diff --git a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/inspectionData/expected.xml b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/inspectionData/expected.xml
index 991ac623f69..8f7807a9cb4 100644
--- a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/inspectionData/expected.xml
+++ b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/inspectionData/expected.xml
@@ -136,15 +136,6 @@
If-Then foldable to '?.'
Foldable if-then
-
- implicitReceiver3.kt
- 5
- light_idea_test_case
- <default>
-
- If-Then foldable to '?.'
- Foldable if-then
-
resultCall.kt
6
diff --git a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/senselessComparison.kt b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/senselessComparison.kt
new file mode 100644
index 00000000000..09c967c8f60
--- /dev/null
+++ b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/senselessComparison.kt
@@ -0,0 +1,10 @@
+// PROBLEM: none
+fun test(foo: Foo) {
+ if (foo != null) {
+ foo.bar()
+ }
+}
+
+class Foo {
+ fun bar() {}
+}
diff --git a/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/uselessIsCheck.kt b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/uselessIsCheck.kt
new file mode 100644
index 00000000000..a8ba5314c24
--- /dev/null
+++ b/idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/uselessIsCheck.kt
@@ -0,0 +1,10 @@
+// PROBLEM: none
+fun test(foo: Foo) {
+ if (foo is Foo) {
+ foo.bar()
+ }
+}
+
+class Foo {
+ fun bar() {}
+}
diff --git a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java
index ca967766193..a191d7a88d9 100644
--- a/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java
+++ b/idea/tests/org/jetbrains/kotlin/idea/inspections/LocalInspectionTestGenerated.java
@@ -757,6 +757,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/rhsNotEqualsNull.kt");
}
+ @TestMetadata("senselessComparison.kt")
+ public void testSenselessComparison() throws Exception {
+ runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/senselessComparison.kt");
+ }
+
@TestMetadata("thenAndElseBothNull.kt")
public void testThenAndElseBothNull() throws Exception {
runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/thenAndElseBothNull.kt");
@@ -787,6 +792,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/unacceptableNoThenBlock.kt");
}
+ @TestMetadata("uselessIsCheck.kt")
+ public void testUselessIsCheck() throws Exception {
+ runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/uselessIsCheck.kt");
+ }
+
@TestMetadata("willNotInlineClassProperty.kt")
public void testWillNotInlineClassProperty() throws Exception {
runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/willNotInlineClassProperty.kt");