if-then to safe access: report even if condition in parentheses #KT-26662 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
6d9fb4f382
commit
b5f73ebd0f
+2
-2
@@ -277,10 +277,10 @@ data class IfThenToSelectData(
|
||||
internal fun KtIfExpression.buildSelectTransformationData(): IfThenToSelectData? {
|
||||
val context = analyze()
|
||||
|
||||
val condition = condition as? KtOperationExpression ?: return null
|
||||
val condition = condition?.unwrapBlockOrParenthesis() as? KtOperationExpression ?: return null
|
||||
val thenClause = then?.unwrapBlockOrParenthesis()
|
||||
val elseClause = `else`?.unwrapBlockOrParenthesis()
|
||||
val receiverExpression = condition.checkedExpression() ?: return null
|
||||
val receiverExpression = condition.checkedExpression()?.unwrapBlockOrParenthesis() ?: return null
|
||||
|
||||
val (baseClause, negatedClause) = when (condition) {
|
||||
is KtBinaryExpression -> when (condition.operationToken) {
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
class Some {
|
||||
fun bar() {}
|
||||
}
|
||||
|
||||
fun Some?.foo() {
|
||||
<caret>if (((this) != null)) {
|
||||
bar()
|
||||
}
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
class Some {
|
||||
fun bar() {}
|
||||
}
|
||||
|
||||
fun Some?.foo() {
|
||||
this?.bar()
|
||||
}
|
||||
+5
@@ -106,6 +106,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/conditionComparesNullWithNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("conditionInParentheses.kt")
|
||||
public void testConditionInParentheses() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/conditionInParentheses.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("conditionInvalidBinaryExp.kt")
|
||||
public void testConditionInvalidBinaryExp() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/branched/ifThenToSafeAccess/conditionInvalidBinaryExp.kt");
|
||||
|
||||
Reference in New Issue
Block a user